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 have this code below which is supposed to redirect a subdomain to a directory in .htaccess. What I am trying to do is make it so that every user on my site has their profile located at username.mysite.com. I already changed the DNS records for a wild card and the code that I have previously worked, but for some reason it isn't anymore. Can anyone help, thanks.

RewriteBase /
RewriteCond s%{HTTPS} ^((s)on|s.*)$ [NC]
RewriteRule ^/*(.+/)?([^.]*[^/])$ http%2://%{HTTP_HOST}/$1$2/ [L,R=301]
RewriteCond %{HTTP_HOST} ^website\.?com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.website\.?com [NC]
RewriteCond %{REQUEST_URI} !/
RewriteRule ^(.*)$ $1 [L]
RewriteBase /
RewriteCond s%{HTTPS} ^((s)on|s.*)$ [NC]
RewriteRule ^/*(.+/)?([^.]*[^/])$ http%2://%{HTTP_HOST}/$1$2/ [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.website\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.website\.com$ [NC]
RewriteCond %{REQUEST_URI} !userdir/
RewriteRule ^(.*)$ userdir/$1 [L]
share|improve this question

2 Answers 2

Have you looked at mod_vhost_alias? It handles this use case out of the box.

share|improve this answer

Start with adding to your Apache config:

RewriteLog /tmp/rwlog.txt
RewriteLogLevel 9

Run a test of the user.website.com and then go disable this (it's hard on performance) and let's see what the logfile has to say. At some point in the log you'll spot where things go awry...

share|improve this answer

Your Answer

 
discard

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