1

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 Answers2

0

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

RewriteRule ^/(.*) /sites/%{HTTP_HOST}/$1
Kevin Collins
  • 1,453
  • 1
  • 10
  • 16
  • Some examples [here](http://cheeso.members.winisp.net/Iirf21Help/html/63be1460-dbd0-4ad4-ad39-4b68352fe9a6.htm) showing how to grab the domain name, separate from the subdomain. – Kevin Collins Nov 09 '11 at 03:10
0

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.

William
  • 3,511
  • 27
  • 35