使用.htaccess共享主机上的多个域

时间:2014-02-11 01:03:33

标签: apache .htaccess mod-rewrite redirect

我想将域重定向到子目录。从关于SO的所有问题来看,这是我能提出的最实用的.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可见。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我相信/test/是一个目录,mod_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]
相关问题