2017-01-23 123 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