Forum Moderators: phranque
eg: I want vic.domainname.com.au/search.php to go to www.domainname.com.au/search.php?state=vic and likewise with all the states. (I'm from Aus...)
I'm trying this:
RewriteCond %{HTTP_HOST} ^vic\.domainname\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.vic\.domainname\.com\.au$
RewriteRule ^(.*)$ /$1 [L]
Which I think should just do the redirect, but even that gives me an error.
Also, I can turn subdomains on and off through my server host, and I seem to get different errors when they're on or off - does anyone know whether they should be on or off and how I can write my rewriterule?
Thanks!
The solution to this problem depends entirely on just what "turn subdomains on and off" means, since it's so ambiguous as to be meaningless. Hosts try to make something complicated simple. But they try to make it too simple, so you have to ask them what it means at the httpd.conf or .htaccess configuration level.
The main problem with the rule is that it rewrites the requested URL-path to itself recursively. And that's not what you said you wanted to do anyway, even if it wasn't an infinite loop.
Based on your description, I'd start with:
RewriteCond %{QUERY_STRING} !&?state=[^&]+
RewriteCond %{HTTP_HOST} !^www\.example\.com\.au
RewriteCond %{HTTP_HOST} ^www\.([a-z])\.example\.com\.au [OR]
RewriteCond %{HTTP_HOST} ^([a-z])\.example\.com\.au
RewriteRule ^search\.php$ search.php?state=%1 [L]
Jim