Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 与.htaccess共享主机上的多个域_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

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]
感谢您的帮助!不客气,是的,尾部斜杠规则也可以。