htaccess集成在现有规则后添加斜杠

时间:2018-07-04 09:53:00

标签: .htaccess

我正在htaccess文件中做几件事:

  • 强制使用https
  • 删除www
  • 删除index.php

我正在使用代理(Cloudflare)

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
AddType text/x-component .htc

如何集成在URL末尾添加斜杠?我有这个代码段,但是当然添加它可以给我多个重定向:

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

1 个答案:

答案 0 :(得分:0)

第二个RewriteCond中缺少斜线。这应该起作用:

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

我还逃过了.中的index.php