.htaccess 的重写规则删除“/”

Rewrite rule for .htaccess delete "/"

我在 url 指向我的网站类型时遇到问题: http://www.domain.com/document.php/ 如果在路由的末尾看到一个“*.php/”或“*.html/”,文档不收取样式,javascripts和函数显示php evil .我希望通过 .htaccess 创建一个规则,如果路由最后是“*.php/”或“*.html/”删除“/”以正常工作。我该怎么做?

.htacess

试试这个
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^([^/]+)\.php/$ .php
  RewriteRule ^([^/]+)\.html/$ .html
</IfModule>

在尝试之前 .htacess 请务必更改 apache2.conf

查找 AllowOverride None 并将 AllowOverride All 替换为指向 htaccess 文件所在的 public 网页的 <Directory> 指令

如果您使用的是ubuntu,您可以在路径/etc/apache2/apache2.conf

下找到apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

这里/var/www/是你的.htacess所在的路径

编辑: @hjpotter 在评论中建议的更好的方法

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^(.+)\.(php|html)/$ .
</IfModule>