Forum Moderators: phranque

Message Too Old, No Replies

[apache] rewrite subdomains to index.php

         

Ruben

1:31 pm on Feb 14, 2008 (gmt 0)

10+ Year Member



From some tutorials and topics i tried to create the following:

[subdomain.domain.tld...] -> index.php?subdomain=subdomain

[subdomain.domain.tld...] ->
index.php?subdomain=subdomain&page=page

I am using the following htaccess, but it doesn't work! Someone can help me?

rewriteCond %{HTTP_HOST} !^www\. [NC]
rewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com(:80)?$

rewriteRule (.*) index.php?subdomain=%1&page=$1 [L]

[edited by: Ruben at 2:07 pm (utc) on Feb. 14, 2008]

jdMorgan

3:14 am on Feb 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Missing some details here, such as where this code is located or what, precisely, does or does not happen when you test your code...

If it's in .htaccess, then you'll have to explicitly prevent an "infinite" rewriting loop:


RewriteCond $1 !index\.php$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com(:80)?$
RewriteRule (.*) index.php?subdomain=%1&page=$1 [L]

Jim

Ruben

12:01 pm on Feb 15, 2008 (gmt 0)

10+ Year Member



Well thanks, that does the trick!