2017-01-23 129 views
0

我有幾個重寫規則在我的.htaccess似乎是衝突。如何解決衝突的mod_rewrite規則和條件

我正在運行ExpressionEngine(CodeIgniter)網站,該網站使用index.php文件解析所有URI。出於美學原因,我從URI中刪除了index.php。

我想實現:

  • 重定向301以斜槓(example.com/bla/ =>
    example.com/bla)
  • 刪除的index.php從所有頁面所有的URI

我現在擁有的一切:

<IfModule mod_rewrite.c> 
    RewriteCond %{HTTPS} !=on 
    RewriteCond %{HTTP_HOST} !^www\. [NC] 
    RewriteCond %{SERVER_ADDR} !=127.0.0.1 
    RewriteCond %{SERVER_ADDR} !=::1 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)/$ /$1 [L,R=301] 
    RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
    RewriteCond $1 !^(images|system|themes|index\.php|admin\.php|favicon\.ico|robots\.txt|humans\.txt|crossdomain\.xml) [NC] 
    RewriteRule ^(.*)$ index.php/$1 [L] 
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] 
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L] 
</IfModule> 

w ^帽子作品:

  • 所有深層鏈接被重定向到非尾隨斜線版本 (example.com/bla/ => example.com/bla)。
  • index.php從所有深度鏈接頁面中刪除。

什麼不起作用:

  • 主頁(example.com)給了我在谷歌瀏覽器的錯誤,說: 「太多的重定向」。

如何更新的條件和規則,使我達到清潔環節沒有結尾的斜線,沒有的index.php,無論哪個頁面是的。

+0

如果用'RewriteRule ^(。+)/ $/$ 1 [L,R = 301]'替換'RewriteRule ^(。*)/ $/$ 1 [L,R = 301]'會怎樣? –

+0

轉到config.php,然後更改$ config ['url_suffix'] =''; –

回答

1

有這樣的:測試前

RewriteCond %{HTTPS} !=on 
RewriteCond %{SERVER_ADDR} !=127.0.0.1 
RewriteCond %{SERVER_ADDR} !=::1 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ /$1 [L,R=301] 

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] 
RewriteRule ^(.*?)index\.php(/.*)?$ /$1$2 [R=301,NE,L] 

RewriteCond $1 !^(images|system|themes|index\.php|admin\.php|favicon\.ico|robots\.txt|humans\.txt|crossdomain\.xml) [NC] 
RewriteRule ^(.*)$ index.php/$1 [L] 

清除瀏覽器緩存。

+0

使用此解決方案,主頁的重定向循環仍然存在。 'example.com'將我重定向到'example.com/index.php','example.com/index.php'將我重定向到'example.com'。任何其他想法? – Rein

+0

清除瀏覽器緩存後嘗試更新我的規則。 – anubhava