重写正则表达式,URL 至少包含一个字符

发布于 2024-08-24 20:12:04 字数 420 浏览 8 评论 0原文

我有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光病人 2024-08-31 20:12:04

您在问题中放入的正则表达式已经确保必须至少有一个字符。 + 表示“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 +.

夏了南城 2024-08-31 20:12:04

...它应该转到默认文档index.cfm,但由于规则,它仍然尝试转发到我的people_details.cfm

那是因为您在末尾有“/”作为可选,这可能不是您想要的通缉。

...it should go to the default document index.cfm, but because of the rule, it still tries to forward to my people_details.cfm

Thats because you have the "/" as optional at the end, which is probably not what you wanted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文