正则表达式抓取字符串直到连字符
我认为我遇到了问题,因为我在此表达式中使用了两个关键的正则表达式值。
RewriteRule ^([^-]*)-([^-]*)-((foot|basket)(ball))-schedule$ /schedule.php?sport=$3&school=$1&year=$2&schedule=true [NC,L]
当有人打字时我会被抓住
domain.com/michigan-1999-football-schedule
。它目前无法识别这个 htaccess 行的字符串,我 99% 它与正则表达式部分有关。我认为这是因为该行的 [^-] 部分。我希望这能抓取数据直到连字符,但我认为存在问题,因为两者都是正则表达式中的关键字符。
I think I'm having an issue since I'm using two key regex values in this expression.
RewriteRule ^([^-]*)-([^-]*)-((foot|basket)(ball))-schedule$ /schedule.php?sport=$3&school=$1&year=$2&schedule=true [NC,L]
I this to be caught when someone types
domain.com/michigan-1999-football-schedule
. It currently doesn't recognize this string with this htaccess line, and I'm 99% it has to do with the regex part. I think it's because the [^-] part of the line. I am hoping this grabs the data until a hyphen, but I think there's an issue since both are key characters in regex.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我来说是有效的。您还有其他正在使用的规则吗?
确保您具备以下条件:
This is working for me as-is. Do you have other rules that you are using?
Make sure that you have the following:
我建议您使用 + 而不是 *,以防某些字段为空:
I would advise you to use + instead of *, in the case some fields would be empty: