Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite -- can't find help on this anywhere

direct subdomain.example.com/d/f.html to subdomain.example2.com/d/f.html

         

joefreshman

5:10 pm on Nov 8, 2007 (gmt 0)

10+ Year Member



I've spent the last 40 minutes trying to find help on this mod_rewrite problem, and haven't been able to figure it out.

Basically, I need to redirect all requests that to sub.example.com to sub.example2.com, preserving the full request_uri. So [sub.example.com...] goes to [sub.example2.com...] I know what example.com and example2.com are, so I can set those statically, but I don't know what "sub" is going to be; they're added dynamically.

My trouble is in figuring out how to extract "sub" out of the original URL to put into the Rewrite Rule. I can't find any good example of how this is done.

jdMorgan

5:23 pm on Nov 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([\.]+)\.example\.com

will put the subdomain into variable %1 so you can back-reference it in the rule, unless the subdomain is "www".

Jim

[edited by: jdMorgan at 5:23 pm (utc) on Nov. 8, 2007]