Bob Cavezza
Bob Cavezza

Reputation: 2850

Regex to grab string until a hyphen

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.

Upvotes: 0

Views: 181

Answers (2)

Mathieu Rodic
Mathieu Rodic

Reputation: 6762

I would advise you to use + instead of *, in the case some fields would be empty:

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

Upvotes: 0

clmarquart
clmarquart

Reputation: 4711

This is working for me as-is. Do you have other rules that you are using?

Make sure that you have the following:

RewriteEngine on
RewriteBase / 

Upvotes: 1

Related Questions