David Martin
David Martin

Reputation: 3

htaccess 301 (permanent) redirection

I need help in 301 permanent URL redirection of dynamic URL's

https://www.xyz.co/certificate.php?certify=iso-haccp should redirect to https://www.xyz.co/certificate/iso-haccp-certification

I want to do it using .htaccess file because there are so many url's like this, help me guys?

Upvotes: 0

Views: 77

Answers (2)

Lucas Willems
Lucas Willems

Reputation: 7073

Try this code :

RewriteEngine On
RewriteCond %{QUERY_STRING} ^certify=(.*)$
RewriteRule ^certificate\.php$ /certificate/%1-certification? [R=301]

Upvotes: 1

AbsoluteƵERØ
AbsoluteƵERØ

Reputation: 7880

A literal redirection would look like this:

RewriteBase /
RewriteCond %{QUERY_STRING} certify=(iso-haccp)
RewriteRule (certificate)\.php /$1/%1-certification? [R=301,L]

We're not using ^ or $ in this example around the query string because it can allow for other variables that could be passed. I'm adding a ? to the end of the redirection string to stop the default behavior of query string append.

Upvotes: 1

Related Questions