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.

How can I change my rewrite rule to keep the original subdomain url in the address bar?

Currently if I type in "username.domain.com" it gets redirected to "domain.com/username"...and I would like the address bar to stay at "username.domain.com".

I'm using wildcard subdomains with this rewrite rule in my httpd.conf file:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
   RewriteRule ^(.*)$ http://domain.com/sites/%2 [L]
</IfModule>

Is this even possible?

Thanks in advance.

share|improve this question
add comment

1 Answer 1

If you change the last line to proxy rather than redirect, I think that will get you the behavior you want:

RewriteRule ^(.*)$ http://domain.com/sites/%2 [P,L]
share|improve this answer
1  
+1 but note that you need mod_proxy enabled for this to work. Be extremely careful when enabling mod proxy! It's somewhat easy to create an open proxy, see the Mod_Proxy page, in particular the ProxyPass directive, for more information. –  Chris S Feb 15 '11 at 20:49
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.