Forum Moderators: phranque
so I tried this rewrite rule but it doesn't work and I don't see what is wrong in it:
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule (.*) http://www.example.com?index.phpvar=$1 [R=301,L]
thanks in advance for your help
[edited by: jdMorgan at 2:02 pm (utc) on Sep. 26, 2007]
[edit reason] example.com [/edit]
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule (.*) http://www.example.com/index.php?var=$1 [R=301,L]
thanks
[edited by: jdMorgan at 2:03 pm (utc) on Sep. 26, 2007]
[edit reason] example.com [/edit]
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule .* /index.php?var[b]=%1[/b] [L]
The second (new) RewriteCond prevents rewriting the "www" subdomain. Delete it if you do want "www" rewritten to the script.
Usually, it is not desirable to use a redirect, because that exposes the underlying subdomain->script mechanism. Here, I show an internal rewrite only, which does not expose the script to clients.
Lastly, what do you intend to do if someone requests subdomain.example.com/some-page-here.php ? The current code will simply discard the URL-path for the requested page.
Jim
[edited by: jdMorgan at 2:06 pm (utc) on Sep. 26, 2007]
RewriteCond %{REQUEST_URI}!^/index\.php$
RewriteCond %{HTTP_HOST}!^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule .* /index.php?var=%1 [L]
Lastly, what do you intend to do if someone requests subdomain.example.com/some-page-here.php?
many thanks for your help
Have you set up wild-card DNS for your subdomains?
Does your host "map" all subdomains to your main 'account' directory?
In addition to adding the rewriterule, these other two steps are also required if not already done.
Jim
Have you set up wild-card DNS for your subdomains?
Just another question for the whole understanding of the process, could you indicate what is the line for setting up wild card DNS?
Is it:
ServerAlias *.example.com
once again, thanks for your great help
The ServerAlias directive you cite is used on the server itself to map the subdomains into your "account space." (Step 2 above)
Jim