Htaccess [SOLVED]: RewriteRule with optional params

Htaccess [SOLVED]: RewriteRule with optional params

Home Forums htaccess Htaccess [SOLVED]: RewriteRule with optional params

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36956

    Anonymous

    QuestionQuestion

    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!

    #36957

    Anonymous

    Accepted AnswerAnswer

    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]
    

    Source: https://stackoverflow.com/questions/47992915/rewriterule-with-optional-params
    Author: Ben
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.