1

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.

Alex
  • 6,603
  • 1
  • 24
  • 32
Ronedog
  • 135
  • 3
  • 6

1 Answers1

4

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]
Alex
  • 6,603
  • 1
  • 24
  • 32
  • 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](http://httpd.apache.org/docs/current/mod/mod_proxy.html) page, in particular the [ProxyPass](http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypass) directive, for more information. – Chris S Feb 15 '11 at 20:49