用mod重写删除尾部斜杠? [英] Removing trailing slashes with mod rewrite?

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

问题描述

这与我以前的问题有关(可以在此处查看).我希望能够从网址中删除斜杠,以便它不会弄乱我网站的某些区域. .htaccess代码在这里:

This relates to my previous question (which can be viewed here). I'd like to be able to remove the trailing slash from the URL so that it doesn't mess up certain areas of my site. The .htaccess code is here:

# -s = File Exists
RewriteCond %{REQUEST_FILENAME} -s [OR]
# -l = Is a SymLink
RewriteCond %{REQUEST_FILENAME} -l [OR]
# -d = Is a Directory
RewriteCond %{REQUEST_FILENAME} -d
# if we match any of the above conditions - serve the file.
RewriteRule ^.*$ - [NC,L]

# only allows '.' in the "page" portion.
RewriteRule ^([^/.]+)/?$ index.php?section=$1 [L]
RewriteRule ^([^/.]+)/([^/]+)/?$ index.php?section=$1&page=$2 [L]
RewriteRule ^([^/.]+)/([^/]+)/([^/.]+)/?$ index.php?section=$1&page=$2&split=$3 [L]

像以前一样,我对此深有感触,所以有人可以帮忙吗?

As before, I'm out of my depth with this, so can anyone help out?

推荐答案

我假设您正在谈论规则:

I assume you are talking about the rule:

RewriteRule ^.*$ - [NC,L]

因为另一个已经省略了斜杠.

As the other already omit the trailing slash.

尝试以下方法:

RewriteRule ^(.*)/$ $1 [NC,L]

这是我在日志中看到的(缩写):

Here's what I see in the logs (abbreviated):

applying pattern '^(.*)/$' to uri 'host/'
rewrite 'host/' -> 'host'

所以我觉得还可以.

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

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