Apache 重写规则,可以使用或不使用尾部斜杠 [英] Apache rewrite rule which works with or without a trailing slash

查看:50
本文介绍了Apache 重写规则,可以使用或不使用尾部斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重定向一系列静态 URL,并且无论是否存在尾随斜杠,我都希望它能够正常工作:

I'm trying to redirect a series of static URLs, and I want it to work whether or not the trailing slash is present:

/foo/bar  --->  /tacos
/foo/bar/  -->  /tacos

我已经尝试了以下方法和各种变体,但我总是只在尾随斜杠出现时匹配:

I've tried the following, and all sorts of variations, but I always get a match only with the trailing slash present:

RewriteRule ^foo/bar?/$ http://url.com/tacos
RewriteRule ^foo/bar(?/)$ http://url.com/tacos
RewriteRule ^foo/bar*/$ http://url.com/tacos
RewriteRule ^foo/bar(*/)$ http://url.com/tacos

我觉得我遗漏了一些明显的东西.帮助?

I feel like I'm missing something obvious. Help?

推荐答案

除了在 EBNFABNF,正则表达式中的量词指的是前面的表达式,而不是后面的表达式.

Other than in EBNF or ABNF, a quantifier in regular expressions refers the preceding expression and not the following expression.

所以:

RewriteRule ^foo/bar/?$ http://url.com/tacos

这篇关于Apache 重写规则,可以使用或不使用尾部斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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