繁体   English   中英

将另一个域重定向到文件夹,而无需更改htaccess的url

[英]Redirect another domain to folder without url changing htaccess

我有一个htaccess重定向(不更改URL)到我的网站所在的文件夹。 最近,我有一个新域名,但无法在该域上使用htaccess代码。

主域:网站的www.test.com文件夹:/ drupal

这是我使用的htaccess代码(因此用户可以访问www.test.com并查看/ drupal内容)

Options -Indexes
RewriteEngine on
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} !^www\.test\.com$ [NC]
RewriteRule .* http://www.test.com/ [L,R=301]
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]
RedirectMatch 301 ^/drupal/$ http://www.test.com/

现在,我在该服务器上有一个新域www.secondtest.com,其内容位于/ drupal2上,但是每当我在浏览器中键入www.secondtest.com时,他就会将我重定向到www.test.com。

有没有办法像这样修改htaccess?

www.test.com (go's invisible to folder) --> www.test.com/drupal 
www.secondtest.com (go's invisible to folder) --> www.test.com/drupal2

您必须使用另一个RewriteCond来检查域:

# Redirection if not www.test.com nor www.secondtest.com
RewriteCond %{HTTP_HOST} !^www\.test\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\.secondtest\.com$ [NC]
RewriteRule .* http://www.test.com/ [L,R=301]

# redirection to drupal folder if test.com
RewriteCond %{HTTP_HOST} ^www\.test\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]

# redirection to drupal2 folder if secondtest.com
RewriteCond %{HTTP_HOST} ^www\.secondtest\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal2/index.php?q=$0 [QSA]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM