问题
Situation (directories tree) on an Apache server:
maindomain.com/
|
|_ .htaccess (just an empty file, no rule in here)
|
|_ addondomain1.com/
| |
| |_ .htaccess
| |_ index.html
|
|_ addondomain2.com/
|
|_ .htaccess
|_ index.html
Currently files in addondomain1.com can be viewed by going to:
http://www.addondomain1.com/index.html
http://www.addondomain1.com/
http://www.addondomain1.com
http://www.maindomain.com/addondomain1.com/index.html
I would like to redirect all requests:
http://maindomain/addondomain1.com/some/path/anypage.html
(with or without 'www')
to same path/file but under addondomain1.com and always with 'www':
http://www.addondomain1.com/some/path/page.html
In order to try to accomplish this, I placed in maindomain.com/addondomain1.com/.htaccess
this rule:
RewriteCond %{HTTP_HOST} !^www\.addondomain1\.com$
RewriteRule ^(.*)$ "http://wwww.addondomain1.com/$1" [R=301,L]
This one works almost great, and redirects well all the ones below:
http://addondomain1.com/index.html >> http://www.addondomain1.com/index.html
http://www.addondomain1.com/ >> http://www.addondomain1.com/
http://www.addondomain1.com >> http://www.addondomain1.com
http://www.maindomain.com/addondomain1.com/index.html >> http://www.addondomain1.com/index.html
http://www.maindomain.com/addondomain1.com/ >> http://www.addondomain1.com/
http://maindomain.com/addondomain1.com/ >> http://www.addondomain1.com/
But unfortunately when going to:
http://maindomain.com/addondomain1.com
http://www.maindomain.com/addondomain1.com
NOTE both links above are WITHOUT final slash, it redirects to:
http://www.addondomain1.com//server/root/path/addondomain1.com
I think the regexp ^(.*)$
is getting "addondomain1.com" as part because the final slash is missing. Do you know how fix/workaorund this issue?
Thanks!
回答1:
DirectorySlash Off
回答2:
Try this:
RewriteCond %{HTTP_HOST} !^www\.addondomain1\.com$
RewriteCond %{REQUEST_URI} ^/[^/]+/(.*)
RewriteRule ^ http://wwww.addondomain1.com/%1 [R=301,L]
来源:https://stackoverflow.com/questions/3242322/apache-mod-rewrite-how-to-redirect-addon-domains-subfolder-access-to-addon-doma