2

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]
2

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

1

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...

Your Answer

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