Removing trailing slashes with mod rewrite?

冷暖自知 提交于 2019-12-20 03:49:09

问题


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?


回答1:


I assume you are talking about the rule:

RewriteRule ^.*$ - [NC,L]

As the other already omit the trailing slash.

Try this instead:

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

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

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

So that seems OK to me.



来源:https://stackoverflow.com/questions/1368276/removing-trailing-slashes-with-mod-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!