IIRF Regex for Domain-based rewrites

614 views Asked by At

I have seen a ton of examples for URL rewrites based on the subdomain, but I am trying to do URL rewrites based on the domain name itself, specifically serve content from a subfolder with the domain name in it.

For instance, I'd like

http://www.site1.com/sub/folders/long-html-filename.htm to be rewritten to either /sites/www.site1.com/sub/folders/long-html-filename.htm or http://www.masterdomain.com/sites/www.site1.com/sub/folders/long-html-filename.htm

I've been able to do a lot of the rewrite regex on my own, but I am hitting a brick wall on this one.

Thanks!

2

There are 2 answers

0
Bill Davidson On BEST ANSWER

Kevin - you were close. The IIRF author got me the rest of the way there:

RewriteRule ^/(?!sites/)(.*)$ /sites/%{HTTP_HOST}/$1

Now I am just trying to figure out how to combine that with a forced-WWW RedirectRule.

Another stumbling block...I have this:

RewriteCond %{HTTP_HOST} ^(?!www)[^\.]+\.[^\.]+$ [I]
RedirectRule ^/(.*) http://www.%{HTTP_HOST}/$1 [R=301]

RewriteRule ^/(?!sites/)(.*)$ /sites/%{HTTP_HOST}/$1

But it doesn't seem to be working, I am just getting a timeout.

1
Kevin Collins On

Have you tried using %{HTTP_HOST} to capture the hostname? Maybe something like this would work:

RewriteRule ^/(.*) /sites/%{HTTP_HOST}/$1