簡體   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