从 htaccess 中的 URL 中删除尾部斜杠 [英] remove trailing slash from URL in htaccess

查看:30
本文介绍了从 htaccess 中的 URL 中删除尾部斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将 htaccess 配置为与我用 PHP 编写的 URL 路由器结合使用.如果从除根 url 之外的 URL 中看到,我正在尝试删除尾部斜杠.我的 htaccess 文件如下所示:

I have my htaccess configured to work in conjunction with a URL Router I've written in PHP. I'm trying to remove a trailing slash if seen from the URL except the root url. My htaccess file looks like this:

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

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

我的网址如下所示:

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

这很好用,但尾部斜线会导致一些问题.(例如)

This works great but a trailing slashe is causing some issues. (e.g.)

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

知道如何删除传入的参数而不是根 URL 的尾部斜杠吗?

Any idea how I can remove the trailing slash for params passed in but not for the root URL?

谢谢,-保罗

推荐答案

RewriteEngine On 下方插入此规则:

Insert this rule just below RewriteEngine On:

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

这篇关于从 htaccess 中的 URL 中删除尾部斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆