skip to Main Content

In accordance with the SEO guidelines I am changing pages url from

website.com/color_red/ (underscore) to

website.com/color-red/ (dash / hyphen)

/color-red/ must simply produce ?c=red

In .htaccess this works perfectly with underscore:

RewriteRule ^color_([^/.]+)/?$ ?c=$1 [L]

not with dash:

RewriteRule ^color-([^/.]+)/?$ ?c=$1 [L]

I think dash char must be escaped but I don’t know how.

2

Answers


  1. Chosen as BEST ANSWER

    A simple solution is to escape the hypen/dash char - with square brackets [-] :

    RewriteRule ^color[-]([^/.]+)/?$ ?c=$1 [L]
    

  2. Could you please try following. Please make sure to clear your browser cache before testing your URLs.

    1st solution: To handle both _ OR - in your URLs then try following.

    RewriteEngine ON
    RewriteRule ^color[_-]([^/]*)/?$ ?c=$1 [L]
    

    2nd solution: In case you only want to handle - in your URLs then try following.

    RewriteEngine ON
    RewriteRule ^color-([^/]*)/?$ ?c=$1 [L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search