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

查看:92
本文介绍了从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下方插入此规则:

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

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

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