skip to Main Content

Previously, I have a redirect rule

RewriteRule ^([A-Za-z0-9-]+)(---[^/]+)/?$ pc.php?name=$1&id=$2 [L,NC,QSA,NE]

1) This gives an output: http://me.com/i-am-here—125/

Now, I want it to change to something better and more SEO friendly. I am using the below rewrite rule.

RewriteRule ^([0-9-]+)/([A-Za-z0-9-]+)/?$ pc.php?id=$1&name=$2 [L]

2) This gives an output: http://me.com/125/i-am-here/

My question: How do I redirect all the old URL (1) to the new URL (2) format?

2

Answers


  1. You can try something like this:

    RewriteRule ^([A-Za-z0-9-]+)(---[^/]+)/?$ $2/$1/ [R=301,NC,L]
    
    Login or Signup to reply.
  2. You can have this redirect rule before your existing rewrite rule:

    RewriteRule ^([A-Za-z0-9-]+)---([^/]+)/?$ /$2/$1/ [R=301,L]
    
    RewriteRule ^([0-9-]+)/([A-Za-z0-9-]+)/?$ pc.php?id=$1&name=$2 [L,QSA]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search