Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)

share|improve this question
add comment

1 Answer

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.