首页 > 解决方案 > 从 htaccess 中的文件扩展名中删除尾部斜杠

问题描述

我正在使用以下条目.htaccess添加条件为!-f的尾部斜杠,当它不是有效文件时应该添加尾部斜杠:

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

现在实际上我以为就是这样,但我最终得到了.png/.php/(基本上只有这两个文件扩展名,这让我很烦)。有没有办法检查结尾是否是.phpor.png然后检查尾随斜杠 - 如果它存在 - 删除它?

编辑:也许是因为其他一些规则.htaccess?我将在此处发布其余部分:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^xxx.net [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


AddDefaultCharset utf-8

order allow,deny
allow from all
deny from 123.249.24.233

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


RewriteCond %{QUERY_STRING} ^$
RewriteCond %{THE_REQUEST} /index\.php
RewriteRule ^index\.php https://www.%{HTTP_HOST}/ [R=301,L]
RewriteRule ^Index\.php$ /index.php [R=301,L]

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

没有“直接”的方法来过滤斜线.php.png结尾吗?

标签: .htaccesstrailing-slash

解决方案


推荐阅读