0

I am trying to make it so that all requests that use a subdomain are rewritten in such a way that they are sent to the server as "regular" request without the subdomain. I have created the mod_rewrite code below but it doesn't seem to be working. Any advice is greatly appreciated.

Options +FollowSymlinks
RewriteEngine on
RewriteRule (.*?).mydomain.com/(.*) http://mydomain.com/$2

I want everything to still appear in the user's address bar window as:

http://subdomain.mydomain.com/$2

(where $2 is whatever path they originally entered in the address bar)

1 Answer 1

1

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule

The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string. If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.

in other words, just lose the host and you are all set

RewriteCond %{REMOTE_HOST} ! mydomain.com  # prevents loops
RewriteRule /(.*) http://mydomain.com/$2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .