htaccess 重定向 - 301 上更严格的匹配?
以下基于 htaccess 的重定向规则工作正常:
Redirect 301 /content/category/2/24/30/ /new/c/url/
问题是它工作得太好了。如果用户访问
/content/category/2/24/30/50/50/
它将重定向到:
/new/c/url/50/50/
如何让它进行严格匹配?将两个示例重定向为简单的:
/new/c/url/
就可以了,否则忽略较长的版本也很好。
谢谢!
The following htaccess based redirection rule works fine:
Redirect 301 /content/category/2/24/30/ /new/c/url/
The problem is it works too well. If a user goes to
/content/category/2/24/30/50/50/
it will redirect to:
/new/c/url/50/50/
How can I get it to do a strict match? Either redirecting both examples to simply:
/new/c/url/
would be fine, otherwise ignoring the longer version is good too.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Redirect
匹配路径前缀和不仅仅是整个路径。如果给定的路径前缀与请求的路径匹配,则从前缀开始的剩余路径将附加到替换路径。因此,请使用
RedirectMatch
代替^
和$
标记路径的开始和结束:Redirect
matches path prefixes and not just the whole path. If the given path prefix matches the requested path, the remaining path from the prefix on is appended to the replacement path.So use
RedirectMatch
instead with^
and$
marking the start and end of the path:解决方案应该是
基本上你说的 30/ 是字符串的结尾。
我无法尝试,所以如果不起作用请告诉我。
^ 匹配字符串的开头,$ 匹配字符串的结尾。
如果您想了解更多信息,请阅读以下内容:http://www.regular-expressions.info/
And the solution should be
Basically you're saying the 30/ is the end of the string.
I can't try it so let me know if it's not working.
^ matches the beginning of a string and $ matches the end of a string.
Read this if you want to know more about it: http://www.regular-expressions.info/