Forum Moderators: phranque
i'm trying to let users have their own subdomains and route user.domain1.tld to domain1.tld/~user/
also i'm tring to use the .htaccess file on many domains, but if it's easier i can create one for each domain,
then the second part tries to say that there is no directory domain1.tld/~user if the user goes there...how they'd find out their files were there i dont know but just incase!
also a wild card CNAME dns record (my hosting company said a CNAME record as opposed to an A record would be better) has been set up for each domain AND (i'm informed) the virtual host info has been updated accordingly.
Well i've tried to figure it out using apache docs and an ilovejackdaniel dot com cheat sheet
i think i've got it ... and then it returns a Internal Server Error code (500 i think)!
the code is as follows and is place in a .htaccess file on each of the domains' root directory, i did experiment with having the domains under a main domain but didn't get on very well with that either!
RewriteEngine On
RewriteCond %{REQUEST_URI}!^/~
RewriteCond %{HTTP_HOST}!^www\.(domain1\.tld¦domain2\.tld¦domain3\.tld)
RewriteCond %{HTTP_HOST} ^([a-z0-9_-]+)\.(domain1\.tld¦domain2\.tld¦domain3\.tld)
RewriteRule (.*) /~%1/$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /~
RewriteRule .* - [R=404]
Please help...!
What's your server error log say when you get a 500 error?
If you are using IE, go into to Internet Options, and turn off anything that says 'Show friendly'. IE hides information that might be very helpful to you as a Webmaster.
I assume you've seen the warnings posted here about the forum dropping spaces between "}" and "!" characters, and changing solid vertical pipes to borken pipes "¦".
Your code is fairly solid, and should work. I'd only make a couple of tweaks to it:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/usr_
RewriteCond %{HTTP_HOST} !^www\.(domain1\.tld¦domain2\.tld¦domain3\.tld)
RewriteCond %{HTTP_HOST} ^([a-z][a-z0-9_-]+[a-z0-9])\.(domain1\.tld¦domain2\.tld¦domain3\.tld)
RewriteRule (.*) /usr_%1/$1 [L]
As implied, get this first part of the code working flawlessly before worrying about preventing direct-entry of the subdomain's subdirectory path.
Jim
the last part about not letting users see their folders should be changed from
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /~
RewriteCond %{THE_REQUEST} ^[a-z][a-z0-9_-]+[a-z0-9]{3,9}\ /usr_
however i noticed in the error logs it said:
RewriteRule: invalid HTTP response code for flag 'R'
RewriteRule .* - R[=404] work? Thanks again for your help
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /usr_([a-z][a-z0-9_-]+[a-z0-9]}/
RewriteRule (.*) http://%1.example.com/$1 [R=301,L]
GET /usr_able123/my_file.html HTTP/1.1
Jim
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /usr_([a-z][a-z0-9_-]+[a-z0-9]}/ should be RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /usr_([a-z][a-z0-9_-]+[a-z0-9])/ notice the ) instead of the } the only problem i have is that
RewriteRule (.*) http://%1.domain.com/$1 [R=301,L] http://abc-123.domain.com/usr_abc-123/ which i can't figure out! Thank for your help though it's been invaluable!
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /usr_[a-z][a-z0-9_-]+[a-z0-9]/
RewriteRule ^usr_([a-z][a-z0-9_-]+[a-z0-9])/(.*) http://$1.example.com/$2 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /usr_
RewriteRule ^usr_([a-z][a-z0-9_-]+[a-z0-9])/(.*) http://$1.example.com/$2 [R=301,L]
Jim