OmniPotens
OmniPotens

Reputation: 1125

htaccess redirect condition to redirect old URL to new URL

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?

Upvotes: 1

Views: 193

Answers (2)

anubhava
anubhava

Reputation: 784908

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]

Upvotes: 0

Ciccio
Ciccio

Reputation: 468

You can try something like this:

RewriteRule ^([A-Za-z0-9-]+)(---[^/]+)/?$ $2/$1/ [R=301,NC,L]

Upvotes: 1

Related Questions