简体   繁体   English

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

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

I have a htaccess redirect (without url change) to a folder where my site is. 我有一个htaccess重定向(不更改URL)到我的网站所在的文件夹。 Recently i got a new domain name, but i can't get the htaccess code working on that domain. 最近,我有一个新域名,但无法在该域上使用htaccess代码。

main domain: www.test.com folder of site: /drupal 主域:网站的www.test.com文件夹:/ drupal

this is the htaccess code i use (so users go to www.test.com and see the /drupal conten) 这是我使用的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/

Now, i have a new domain www.secondtest.com on that server, which content stands on /drupal2 but whenever i type www.secondtest.com into my browser he redirects me to www.test.com . 现在,我在该服务器上有一个新域www.secondtest.com,其内容位于/ drupal2上,但是每当我在浏览器中键入www.secondtest.com时,他就会将我重定向到www.test.com。

Is there a way to modify the htaccess like so? 有没有办法像这样修改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

You have to use an another RewriteCond to check the domain : 您必须使用另一个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