.htaccess - 从 htaccess 中的文件扩展名中删除尾部斜杠
问题描述
我正在使用以下条目.htaccess
添加条件为!-f
的尾部斜杠,当它不是有效文件时应该添加尾部斜杠:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R]
现在实际上我以为就是这样,但我最终得到了.png/
和.php/
(基本上只有这两个文件扩展名,这让我很烦)。有没有办法检查结尾是否是.php
or.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
结尾吗?
解决方案
推荐阅读
- c# - AKS 集群 pod kube 配置位置
- java - 使用带有 Notepad ++ 和 windows cmd 的 pdfbox?
- monitoring - OpenTracing 和 Zipkin 之间的主要区别是什么?
- java - Java 编程 - 基于流程图的编码
- docker - 无法将命令行选项传递给 Gitlab CI 服务?即“-p 4444:4444 -p 5900:5900”
- python - 加载具有一列字符串而其余浮动的numpy数组的最快方法
- excel - Excel VBA 调整表格大小复制公式和形状
- javascript - Syled Component 渲染一个 React 组件
- java - Apache POI - 如何在特定单元格启动我的 cellIterator?
- error-handling - 使用问号 (?) 运算符时发生错误时如何记录到文件?