2012-12-21 61 views
0

我有一個域名,如example.test.com。該網站由三個不同的HTML文件:mod_rewrite在Chrome和Internet Explorer中無法在Firefox中使用

  • 的index.html
  • products.html放在
  • contact.html

因此,如果example.test.com/index.html用戶鍵入的URL應該被重定向到example.test.com

而且example.test.com/index應該成爲example.test.com

example.test.com/contact.html應該example.test.com/contact等。

他們應該是沒有www之前的url。

我想出了以下規則:

RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} !^example.test.com$ [NC] 
RewriteRule ^(.*)$ http://example.test.com/$1 [L,R=301] 

RewriteCond %{SCRIPT_FILENAME}/ -d 
RewriteCond %{SCRIPT_FILENAME}.html !-f 
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L] 

RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
RewriteRule ^(.+)\.html$ /$1 [R=301,L] 

RewriteCond %{SCRIPT_FILENAME}.html -f 
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?|php)\ HTTP/ 
RewriteRule ^index\.(html?|php)$ http://example.test.com/ [R=301,L] 

在Firefox中一切正常,但在Chrome和Internet Explorer example.test.com/index.html只重定向到example.test.com/index,我不知道爲什麼。

回答

1

我不確定你想用^[A-Z]{3,9}\部分實現的目標,但這裏的罪魁禍首是你最後一個條件的索引末尾的點。更改爲:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index(|\.html|\.php)\ HTTP/ 
RewriteRule ^index\.(html?|php)$ http://example.test.com/ [R=301,L] 

這應該可以正常工作。

相關問題