将另一个域重定向到文件夹而不更改htaccess

时间:2014-04-03 11:12:09

标签: apache .htaccess mod-rewrite redirect

我有一个htaccess重定向(没有更改网址)到我的网站所在的文件夹。最近我得到了一个新的域名,但我无法获得该域名的htaccess代码。

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

这是我使用的htaccess代码(所以用户访问www.test.com并查看/ drupal conten)

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

1 个答案:

答案 0 :(得分:0)

您必须使用另一个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]
相关问题