Forum Moderators: phranque

Message Too Old, No Replies

puzzles on using mod_rewrite to implement virtual subdomains.

subdomain using mod_rewrite

         

fragttdg

7:08 am on Nov 24, 2005 (gmt 0)

10+ Year Member



I've been punching my head against the wall digging this awesome module. So far I could not get everything work. I come here for all you genius' help. Any update will be greatly appreciated.
(I have full access to the apache server.)
I need to redirect the following urls:
www. domain.com
-> no redirection
domain.com
-> www.domain.com
sub.domain.com
-> www.domain.com/AAA/BBB/index.php?udn=sub
sub.domain.com/funny
-> www.domain.com/AAA/BBB/funny.php?udn=sub

Thanks your time and input!

jdMorgan

6:49 pm on Nov 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



fragttg,

Your post has been waiting for awhile, so I'll give it a shot, although we prefer that you post your own ocde for comment. Assuming that you're familiar with the setup and use of mod_rewrite:


RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^$ /AAA/BBB/index.php?udn=%1 [L]
#
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^funny$ /AAA/BBB/funny.php?udn=%1 [L]

Only the first case is an external redirect; The others are internal rewrites, on the assumption that you probably do not want to 'expose' the internal workings of your site's subdomain-handling.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim