[英]Remove trailing slash and create query string with .htaccess
In my .htaccess file, I would like to remove the trailing slash from the URL without modifying the current setup for the query string. 在我的.htaccess文件中,我想从URL中删除结尾的斜杠,而无需修改查询字符串的当前设置。
I tried this in a two-step fashion, but it's not working as I expect: 我分两步进行了尝试,但效果不理想:
# Remove trailing slash
RewriteRule ^(.+)/$ $1 [R=301]
# Create query string from canonical URL
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Cheers 干杯
You can use: 您可以使用:
RewriteEngine On
RewriteBase /site/dev/
## Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ $1 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.