Culvanen
Culvanen

Reputation: 27

RewriteRule with optional params

I have been trying for several hours to modify a URL by including optional parameters

My rewriting rules do not work

It consists of an ID, a slug and the two optional parameters are "-season- {number} -" and "-episode -" {number} "

I think the problem is that the slug sometimes contains a dash at the end.

RewriteRule ^serie-([0-9]+)(-([a-z0-9/-]))? serie.php?id=$1&sl=$2 [L]

RewriteRule ^serie-([0-9]+)-([a-z0-9/-])-saison-([0-9]+)-episode-([0-9]+)$ /serie.php?id=$1&sl=$2&esid=S$3-E$4 [L]

I want this result:

serie-1-the-strain

and with optional params:

serie-1-the-strain-saison-17-episode-259

Thanks or your help!

Upvotes: 0

Views: 92

Answers (1)

Ben
Ben

Reputation: 5139

You should update the RewriteRule as:

RewriteRule ^serie-([0-9]+)-([a-z0-9/-]+)-saison-([0-9]+)-episode-([0-9]+)$ /serie.php?id=$1&sl=$2&esid=S$3-E$4 [L]

RewriteRule ^serie-([0-9]+)(-([a-z0-9/-]+))? serie.php?id=$1&sl=$3 [L]

Upvotes: 1

Related Questions