Apache 与.htaccess共享主机上的多个域
我想要一个域重定向到一个子目录。从所有的问题来看,这是我能想到的最实用的Apache 与.htaccess共享主机上的多个域,apache,.htaccess,mod-rewrite,redirect,Apache,.htaccess,Mod Rewrite,Redirect,我想要一个域重定向到一个子目录。从所有的问题来看,这是我能想到的最实用的.htaccess设置,但它并不完全正确 RewriteCond %{HTTP_HOST} ^(www\.)?otherdomain\.com$ [NC] RewriteCond %{REQUEST_URI} !other-domain-dir/ [NC] RewriteRule ^(.*)$ /other-domain-dir/$1 [L] 它在主页上运行得非常好。导航到otherdomain.com会按预期返回inde
.htaccess
设置,但它并不完全正确
RewriteCond %{HTTP_HOST} ^(www\.)?otherdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !other-domain-dir/ [NC]
RewriteRule ^(.*)$ /other-domain-dir/$1 [L]
它在主页上运行得非常好。导航到
otherdomain.com
会按预期返回index.html。但是,如果我转到otherdomain.com/test
,我会被重定向到otherdomain.com/other domain dir/test/
,这样可以正确加载页面,但我不希望看到other domain dir
。如何修复此问题?我相信/test/
是一个目录,mod\u dir
首先添加了一个尾部斜杠
请尝试以下代码:
RewriteCond %{HTTP_HOST} ^(www\.)?otherdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !/other-domain-dir/ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)/?$ /other-domain-dir/$1 [L]
RewriteCond %{HTTP_HOST} ^(www\.)?otherdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !/other-domain-dir/ [NC]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+?)/$ /other-domain-dir/$1 [L]
除了你的建议之外,我还在上面添加了这个
#如果目录中不存在尾随斜杠
RewriteRule^([^\.]+[^/])$http://%{http_HOST}/$1/[R=301,L]
感谢您的帮助!不客气,是的,尾部斜杠规则也可以。