2012-09-10 319 views
0

我想在.htaccess中使用重寫規則來重寫從子域(michigan.sitename.com)到url的訪問權限 - 在本例中爲http://sitename.org/content/michigan-21st-century-community-learning-centers如何將子域重寫爲url

該網站基於Drupal。

這就是我到目前爲止,頭幾行是來自Drupal的,換行後的所有內容都是來自我的。

我得到一個404錯誤試圖子域

RewriteEngine on 
    # Rewrite URLs of the form 'x' to the form 'index.php?q=x'. 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !=/favicon.ico 
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 

    # New information for Michigan sub domain 
    RewriteCond %{HTTP_HOST} . 
    RewriteCond %{HTTP_HOST} !^michigan.sitename\.com 
    RewriteRule (.*) http://www.sitename.com/$1 [R=301, L] 

任何意見將是有益的

回答

0

更改您的規則從:

RewriteCond %{HTTP_HOST} . 
RewriteCond %{HTTP_HOST} !^michigan.sitename\.com 
RewriteRule (.*) http://www.sitename.com/$1 [R=301, L] 

要:

RewriteCond %{HTTP_HOST} . 
RewriteCond %{HTTP_HOST} ^michigan\.sitename\.com 
RewriteRule (.*) http://www.sitename.com/content/michigan-21st-century-community-learning-centers [R=301,L] 

你有一個空間後部呃R=301, mod重寫不喜歡,它會假設有另一個參數和puke。你也想刪除!因爲你想匹配密歇根子域。該URI也將被忽略,這意味着如果你去:

http://michigan.sitename.com/ 
http://michigan.sitename.com/foo/bar 
http://michigan.sitename.com/blah.html 

都會重定向到:

http://sitename.org/content/michigan-21st-century-community-learning-centers 

您也想交換與New information for Michigan sub domain使得密歇根Rewrite URLs of the form 'x' to the form 'index.php?q=x'.規則重定向首先發生,否則請求將通過index.php路由。或者,你可以添加額外的條件,您的index.php規則:

RewriteCond %{HTTP_HOST} !^michigan\.sitename\.com 
+0

它仍然給我一個404錯誤。 –

0

您必須首先將密歇根規則(休息,看到喬恩林的回答):

RewriteEngine on 

    # New information for Michigan sub domain 
    RewriteCond %{HTTP_HOST} ^michigan\.sitename\.com 
    RewriteRule . http://www.sitename.com/content/michigan-21st-century-community-learning-centers [R=301,L] 

    # Rewrite URLs of the form 'x' to the form 'index.php?q=x'. 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !=/favicon.ico 
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]