Royer Royer - 1 month ago 6
Apache Configuration Question

How to create a 301 redirect for new product URL in htaccess

I have the following problem.

My website has changed the cms and the product URLS are different. They used to look like this:

domain.com/old-link/?a1=291&b2=23&c3=92


The new one however looks like this:

domain.com/new-one/291-23-92


How can I create a redirect for all products that look like that using .htaccess?

Thank you

Answer

You can use the following rule :

RewriteEngine on


RewriteCond %{THE_REQUEST} /old-link/\?a1=([^&]+)&b2=([^&]+)&c3=([^&]+)\sHTTP [NC]
RewriteRule ^ /new-link/%1-%2-%3? [L,R]