Bob Cavezza
Bob Cavezza

Reputation: 2850

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

RewriteRule ^([^-]*)-([^-]*)-((foot|basket)(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)

Upvotes: 0

Views: 375

Answers (1)

anubhava
anubhava

Reputation: 784908

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

Upvotes: 1

Related Questions