重写正则表达式,URL 至少包含一个字符
我有以下 RewriteRule:
RewriteRule ^/people/([A-Za-z0-9\-\_]*)/?$ /people/people_details.cfm?person=$1 [I,L]
...它非常适合转发我的规则,但我想确保正则表达式仅在它具有多个字符时才选择它。所以说真的,我需要让我的正则表达式......
[A-Za-z0-9\-\_]+
有一条附加规则来说明必须至少有一个字符。现在如果我去...
/people/
...它应该去默认文档index.cfm,但由于规则,它仍然尝试转发到我的people_details.cfm
有帮助吗?
谢谢, 乔治
I have the following RewriteRule:
RewriteRule ^/people/([A-Za-z0-9\-\_]*)/?$ /people/people_details.cfm?person=$1 [I,L]
...it works great for forwarding my rule, but I want to make sure that the regex only picks it up if it has more than one character. So really, I need to have my regex...
[A-Za-z0-9\-\_]+
...have an additional rule to say that there has to be at least one character. Right now if I go to...
/people/
...it should go to the default document index.cfm, but because of the rule, it still tries to forward to my people_details.cfm
Any help?
Thanks,
George
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在问题中放入的正则表达式已经确保必须至少有一个字符。
+
表示“1 或更多”,而*
表示“零或更多”。只需将*
更改为+
即可。Your regular expression that you put in your question already ensures that there must be at least one character. The
+
means "1 or more", as opposed to*
which means "zero or more". Just change the*
to a+
.那是因为您在末尾有“/”作为可选,这可能不是您想要的通缉。
Thats because you have the "/" as optional at the end, which is probably not what you wanted.