Fernando Carvalho
Fernando Carvalho

Reputation: 19

.htaccess 301 redirect url´s with parameters

I have a problem redirecting my url´s with parameters.

My url´s look like this:

www.my-site.com/catalogo.php?cat=xxx

and it´s rewriting to:

www.my-site/xxx

That´s working fine the rewriting! But know, google is indexing both url´s and have to make a rule to redirect the url with parameters to the friendly url. Had tryed many solutions that find googling, but only one worked and was redirecting to domain root.

I want to do this redirects:

www.my-site.com/catalogo.php?cat=xxx to www.my-site/xxx

www.my-site.com/catalogo.php?cat=xxx&scat=yyy to www.my-site/xxx/yyy

www.my-site.com/product.php?cat=xxx&scat=yyy&name=zzz&id=xyz to www.my-site/xxx/yyy/zzz/xyz

Upvotes: 0

Views: 54

Answers (1)

anubhava
anubhava

Reputation: 785186

Have it this way:

RewriteCond %{THE_REQUEST} /catalogo\.php\?cat=([^\s&]+)\s [NC]
RewriteRule ^ /%1? [R=302,L,NE]

RewriteCond %{THE_REQUEST} /catalogo\.php\?cat=([^\s&]+)&scat=([^\s&]+)\s [NC]
RewriteRule ^ /%1/%2? [R=302,L,NE]

RewriteCond %{THE_REQUEST} /catalogo\.php\?cat=([^\s&]+)&scat=([^\s&]+)&name=([^\s&]+)&id=([^\s&]+)\s [NC]
RewriteRule ^ /%1/%2/%3/%4? [R=302,L,NE]

Upvotes: 1

Related Questions