0

This code 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?

1
  • Please provide 1 or better 2 URL examples (from URL => to URL) -- it's much more easier to work with URLs and build my own rules rather than trying to figure out what this code supposed to do without having any clues on URLs.
    – LazyOne
    Aug 25, 2011 at 23:00

1 Answer 1

1

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/.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.