重写URL以删除%(如果它是URL中的最后一个字符) [英] Rewrite a URL to remove the % if it's the last character in the URL
本文介绍了重写URL以删除%(如果它是URL中的最后一个字符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果%字符是URL中的最后一个字符,是否可以将其删除?
Is it possible to remove a % character if it is the last character in a URL?
我想重定向如下内容: http://www.mydom.com/foo% 到
I would like to redirect something like: http://www.mydom.com/foo% to http://www.mydom.com/foo
我已经采取了一些措施,以确保不会以这种方式结束系统中生成的URL,但是我们要考虑的是已经被书签或索引为末尾%字符的任何URL.
I've already taken some steps to ensure no URLs are generated from my system that end that way, but we want to account for any that already were bookmarked or indexed with the ending % character.
推荐答案
应该很简单:
RewriteEngine On
RewriteRule (.*)%$ $1 [R,L]
- 只要最后一个字符是
-
(.*)
就会捕获任何内容 -
$ 1
将包含(.*)
的内容,并可用作URL重写为 (.*)
will capture anything as long as the last character is a%
$1
will contain the contents of(.*)
and can be used as the URL to rewrite to
%
,
这篇关于重写URL以删除%(如果它是URL中的最后一个字符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文