Change htaccess path?
This co开发者_C百科de works. What it does is rewrite's a subdomain so a specific directory will display. Basically it enables wildcard domains to exist.
Currently it does this.
bob.domain.com
goes to public_html/-bob
I would like it to go to public_html/__sites/-bob
. I tried the code below at the bottom but didn't have any joy. Help would be appreciated.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/-
RewriteCond %{HTTP_HOST} ^([^\./]+)
RewriteCond %{DOCUMENT_ROOT}/-%1 -d
RewriteRule ^(.*)$ -%1/$1 [L]
However it doesn't do what I want it to do.
Instead of it redirecting to root/-directory
I want it to redirect to root/__sites/-directory
I have tried this but I get a server error
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/-
RewriteCond %{HTTP_HOST} ^([^\./]+)
RewriteCond %{DOCUMENT_ROOT}/__sites/-%1 -d
RewriteRule ^(.*)$ __sites/-%1/$1 [L]
How do I tweak this code to get it working?
As I understand you having 500 Internal Server Error. If you check your error log, there will be detailed explanation on the reason that caused it. I'm pretty sure it will be "Number of iterations exceeded" or something like that.
Considering my assumption is correct, this will be the correct rule:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/__sites/
RewriteCond %{HTTP_HOST} ^([^\./]+)
RewriteCond %{DOCUMENT_ROOT}/__sites/-%1 -d
RewriteRule ^(.*)$ __sites/-%1/$1 [L]
The error caused by the fact that rewrite is not stopped when you specify the [L]
flag -- it only goes to next iteration .. where your current rule will be executed again .. and again.
You have updated destination path from public_html/-bob
to public_html/__sites/-bob
.. but forgot to update the very first condition: should be %{REQUEST_URI} !^/__sites/
.
精彩评论