开发者

Regex Rewrites stop at hyphen but allow hyphen in the string (.htaccess)

开发者 https://www.devze.com 2023-03-02 10:12 出处:网络
RewriteRule ^([^-]*)-([^-]*)-((foot|baske开发者_如何学Got)(ball))-schedule(/)?$ /yearschedule.php?sport=$3&school=$1&year=$2&schedule=true [NC,L]is the current code.

RewriteRule ^([^-]*)-([^-]*)-((foot|baske开发者_如何学Got)(ball))-schedule(/)?$ /yearschedule.php?sport=$3&school=$1&year=$2&schedule=true [NC,L] is the current code.

I goofed and didn't realize the basketball schedules would also include a hyphen. How would I change this code to allow the rewrites to recognize the basketball page years correctly?

Doesn't work correctly

http://domain.com/michigan-1999-00-basketball-schedule 

Works Correctly

http://domain.com/michigan-1999-football-schedule

The problem is that the rewrite doesn't recognize the format because in the eyes of the server, it stops the basketball years at 1999-|here|00 instead of following through. I'm really not sure what code I should use to fix this.

(regex novice)


Try this line instead:

RewriteRule ^([^-]*)-([^-]*)-((foot|(?:[^-]*-)?basket)(ball))-schedule/?$ /yearschedule.php?sport=$3&school=$1&year=$2&schedule=true [NC,L]

It will match following:

  • http://domain.com/michigan-1999-00-basketball-schedule
  • http://domain.com/michigan-1999-basketball-schedule
  • http://domain.com/michigan-1999-football-schedule
0

精彩评论

暂无评论...
验证码 换一张
取 消