简体   繁体   English

从htaccess中的URL删除尾部斜杠

[英]remove trailing slash from URL in htaccess

I have my htaccess configured to work in conjunction with a URL Router I've written in PHP. 我已将hta​​ccess配置为与我用PHP编写的URL路由器一起使用。 I'm trying to remove a trailing slash if seen from the URL except the root url. 我正在尝试从URL(根URL除外)中删除尾部的斜杠。 My htaccess file looks like this: 我的htaccess文件如下所示:

Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]

My URLs look like this: 我的网址如下所示:

http://my-site-domain.com/login

This works great but a trailing slashe is causing some issues. 这很好用,但是斜杠后面会引起一些问题。 (eg) (例如)

http://my-site-domain.com/login/

Any idea how I can remove the trailing slash for params passed in but not for the root URL? 知道如何删除传入的参数的末尾斜杠,但不能删除根URL的末尾斜杠吗?

Thanks, -Paul 谢谢-保罗

Insert this rule just below RewriteEngine On : 将此规则插入到RewriteEngine On下方:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]

For those who are still running into this problem, I solved mine by adding a question mark just after the slash before the dollar sign, like this: 对于那些仍然遇到此问题的人,我通过在美元符号前的斜杠后添加一个问号来解决我的问题,如下所示:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ /$1 [R=302,NE,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM