I need some help on the htaccess subdomain to be pointed to specific file in a folder.
Inside the parent folder should contain individual php files to correctly path the right applications. Sounds simple here.
The url that the user has type should not change / redirect, instead it should only "link" to the correct file at the background
Example when user type userbase.company.com it should point to
http://company.com/parent/userbase.php
Similarly, when user type userbase2.company.com it should point to
http://company.com/parent/userbase2.php
but no redirection should happen. url links should remain at
http://userbase2.company.com
folder would be the same, but not the file. Is it possible?
Currently I have this htaccess code:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^userbase.company.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.userbase.company.com$
RewriteRule ^(.*)$ \./parent/userbase.php/$1 [L]
I'm going have to put this at /public_folder/ right? Not at the /public_folder/userbase ?
This rule should do the job:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/parent/
RewriteCond %{HTTP_HOST} !=domain.com
RewriteCond %{HTTP_HOST} !=www.domain.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$
RewriteRule (.*) /parent/%1.php%{REQUEST_URI} [L]
URL will remain unchanged in browser (means rewrite -- internal redirect).
It will only work for
something.domain.com(notdomain.comorwww.domain.com).It will rewrite this request
http://user1.company.com/hello/pink/kitten.phpinto/parent/user1.php/hello/pink/kitten.phpIf subdomain is complex (e.g.
www.something.domain.com) then it will be reflected in rewrite as well: e.g.http://www.something.company.com/hello/pink/kitten.phpwill be rewritten to/parent/www.something.php/hello/pink/kitten.php. If such behaviour is undesired (I do not know your requirements for 100%) then you will need add 1 more condition to the rule.Request for a home page (e.g.
http://user1.company.com/) will be rewritten in this way:/parent/user1.php/
P.S. Rule was tested before posting -- works fine, but you have to check and maybe tweak it if it needs to be working with your CodeIgniter app (sorry, I'm not familiar with that framework).
In any case this rule should be above your CodeIgniter rewrite rules (if there are such).
来源:https://stackoverflow.com/questions/6831091/htaccess-subdomain-pointing