2011-11-20 142 views
0

我有我的網站有巨大的重複問題。首先,我將非www轉向www,工作正常。.htaccess重定向index.php文件

RewriteEngine on 
rewritecond %{http_host} ^example.com [nc] 
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc] 

但我的網站仍然是通過URL的index.php訪問 爲了解決這個問題我修改爲:

RewriteEngine on 
rewritecond %{http_host} ^example.com [nc] 
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc] 
RewriteCond %{THE_REQUEST} ^.*/index.php 
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L] 

它工作得很好,但我有CMS登錄的麻煩,它不會讓我登錄到我的CMS。 然後我說這個:

RewriteCond %{REQUEST_URI} !^/admin/ 
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L] 

它仍然didnt讓我登錄到我的CMS。我確切CMS網址是:

www.example.com/admin/index.php

+0

添加'的RewriteCond%{REQUEST_METHOD} POST',以防止被重定向被清除後的數據! (搜索引擎不發送任何帖子請求,所以沒問題) – Gerben

回答

1

Darthenius是正確的,但忘了提一兩件事:用大寫正確(即使是沒有必要的,它總是一個好習慣拿):

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

RewriteCond %{REQUEST_URI} !(/admin/index\.php) 
RewriteCond %{REQUEST_URI} ^.*/index.php 
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L] 

請告訴我,如果它的工作原理

相關問題