Forum Moderators: phranque
Currently I have this...
RewriteEngine on
#
RewriteCond %{REQUEST_URI} ^/([/A-Za-z0-9_]*)?([A-Za-z0-9_]+)$
RewriteRule ^(.*) [mydomain.com...] [R]
Which takes [mydomain.com...] and redirects it to [mydomain.com...]
However I am looking for some code to do this...
[whatever.mydomain.com...] and redirects it to [mydomain.com...]
I hope this makes sense.. thank you in advance
RewriteCond %{REQUEST_URI}!^/index\.php
RewriteCond %{HTTP_HOST}!^www\.
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com
RewriteRule ^(.*) [mydomain.com...] [L]
RewriteCond %{REQUEST_URI} ^/([/A-Za-z0-9_]*)?([A-Za-z0-9_]+)$
RewriteRule ^(.*) [mydomain.com...] [R]
Welcome to WebmasterWorld!
The URL-path in the first line must match the name of the target script in the RewriteRule. The function of the first line is to prevent rewrite looping.
In order to avoid revealing your script's function, I'd also recommend using an internal rewrite, rather than a redirect (this could be a security issue). The RewriteRule changes as shown:
RewriteCond %{REQUEST_URI} !^/[b]script[/b]\.php
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com
RewriteRule (.*) [b]/script[/b].php?%1 [L]