我的.htaccess文件中给出了以下规则,所有功能都可以正常运行,只有一个例外:
#Active mod_rewrite
RewriteEngine on
#Name of APP
RewriteBase /web
#DirectorySlash Off
Options -MultiViews
#Remove web/ from URLs using a redirect rule
RewriteCond %{THE_REQUEST} \s/+(.+/)?web/(\S*) [NC]
RewriteRule ^ /%1%2? [R=301,L,NE]
#Disable WWW
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
#Active HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} assets/(css|fonts|js|img)/(.+)$
RewriteRule ^(.*)$ assets/%1/%2 [L,R]
#Add slash at the end (/)
#RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
RewriteRule ^([a-zA-Z0-9-/]+)$ product.php?id=$1
该异常的错误是,当我尝试通过以下方式始终在URL中启用斜杠/结尾时:
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
而且,这样做会丢失文件排除规则
RewriteCond %{REQUEST_URI} assets/(css|fonts|js|img)/(.+)$
RewriteRule ^(.*)$ assets/%1/%2 [L,R]
而且,更糟糕的是,当我尝试访问产品时,它会在URL中显示
https://example.org/product.php/?id=mi-producto-de-url-amigable/?
一团糟,我已经浏览了一些文章,也通过这种方式,我尝试了每篇文章中建议的替代方法RewriteRule ^(.*[^/]$) $1/ [R,QSA,L]
,但除其他外没有成功。
答案 0 :(得分:0)
您尝试过吗?
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]