2015-12-21 70 views
0

我的服務器。 htaccess的規則是這樣的:.htaccess規則導致內部服務器錯誤,但它們看起來正確

RewriteEngine On 
# first redirect 
RewriteCond %{HTTP_HOST} ^www\.testing\.examplewebsite\.co\.uk$ [OR] 
RewriteCond %{HTTP_HOST} ^testing\.examplewebsite\.co\uk$ [NC] 
RewriteRule ^(.*)$ https://testing.examplewebsite.com/$1 [L,R=301] 

# second redirect 
RewriteCond %{HTTP_HOST} ^www\.test\.examplewebsite\.co\.uk$ [OR] 
RewriteCond %{HTTP_HOST} ^test\.examplewebsite\.co\uk$ [NC] 
RewriteRule ^(.*)$ https://test.examplewebsite.com/$1 [L,R=301] 

# Main redirect 
RewriteCond %{HTTP_HOST} ^www\.examplewebsite\.co\.uk$ [OR] 
RewriteCond %{HTTP_HOST} ^examplewebsite\.co\uk$ [NC] 
RewriteRule ^(.*)$ https://examplewebsite.com/$1 [L,R=301] 

# All subdomains that don't exist redirect 
RewriteCond %{HTTP_HOST} ^(.+)\.examplewebsite\.co\.uk$ [NC] 
RewriteRule^https://www.examplewebsite.com/ [L,R] 

但由於某些原因沒有它會導致服務器內部錯誤,我不知道,如果他們都是100%正確任。像最後一條規則一樣,在起始處也應該使用^(.*)$,在末尾使用$1

同樣的標誌,不太確定它們是否全部正確。

基本上我試圖讓:

  • testing.examplewebsite.co.ukwww.testing.examplewebsite.co.ukhttps://testing.examplewebsite.com
  • test.examplewebsite.co.ukwww.test.examplewebsite.co.ukhttps://test.examplewebsite.com
  • 其他一些子域像上面
  • examplewebsite.co.ukwww.examplewebsite.co.ukhttps://examplewebsite.com
  • 使所有使用的域名,例如stackoverflow.examplewebsite.co.ukwww.stackoverflow.examplewebsite.co.uk都被髮送到https://examplewebsite.com
+0

在添加這些規則之前,您的.htaccess工作嗎?你有沒有檢查你的錯誤日誌? –

+0

是的,在我的日誌中沒有錯誤:( – Ryflex

+1

你不能看到正確的apache日誌,它會顯示爲什麼會有500錯誤,很可能是它不能識別'RewriteEngine'刪除第一行RewriteEngine,看看你是否仍然有錯誤 –

回答

2

你有你的所有條件,一個錯字。您行中的第二個條件在uk之前缺少.。^testing.examplewebsite.co.uk $ [NC]

RewriteEngine On 
# first redirect 
RewriteCond %{HTTP_HOST} ^www\.testing\.examplewebsite\.co\.uk$ [OR] 
RewriteCond %{HTTP_HOST} ^testing\.examplewebsite\.co\.uk$ [NC] 
RewriteRule ^(.*)$ https://testing.examplewebsite.com/$1 [L,R=301] 

# second redirect 
RewriteCond %{HTTP_HOST} ^www\.test\.examplewebsite\.co\.uk$ [OR] 
RewriteCond %{HTTP_HOST} ^test\.examplewebsite\.co\.uk$ [NC] 
RewriteRule ^(.*)$ https://test.examplewebsite.com/$1 [L,R=301] 

# Main redirect 
RewriteCond %{HTTP_HOST} ^www\.examplewebsite\.co\.uk$ [OR] 
RewriteCond %{HTTP_HOST} ^examplewebsite\.co\.uk$ [NC] 
RewriteRule ^(.*)$ https://examplewebsite.com/$1 [L,R=301] 

# All subdomains that don't exist redirect 
RewriteCond %{HTTP_HOST} ^(.+)\.examplewebsite\.co\.uk$ [NC] 
RewriteRule^https://www.examplewebsite.com/ [L,R] 
+0

那麼最後一條規則呢,我應該使用'^'還是'^ (。*)$'或其他東西,我不明白重寫規則的那部分是什麼,除此之外,是的,我現在看到了這個錯誤,真是令人尷尬 – Ryflex

+1

在最後一行,只有當你還想要將任何文件或子文件夾重定向到O操作。由於這些子域名不存在,所以應該保留最後一條規則。 –

相關問題