I have a server running, which is a webserver as well as a DNS server. I've configured bind to accept any wildcard subdomain (*.mydomain.com). Now, I'd like for users to be able to use username.mydomain.com to view their profile page.

So far, I've succeeded to redirect username.mydomain.com to mydomain.com/username with the following lines in my Apache configuration file:

RewriteCond %{HTTP_HOST} !^www.* [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com
RewriteRule ^(.*) http://mydomain.com/%1$1 [R=301,QSA,L]

When I type, for example http://rik.mydomain.com, it redirects to http://mydomain.com/rik, which is what I want, but the URL also changes in the address bar of my browser. Is there any way to redirect username.mydomain.com to a folder, and keep username.mydomain.com in the address bar?

I can't use a separate Apache configuration file for the subdomains, as there are to many subdomains (for each user).

Thanks in advance


Try removing the "R=301," from your rewrite rule. That should prevent the server from telling the browser to change the displayed domain name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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