technico
technico

Reputation: 113

Htaccess Redirection 301 FROM "with parameter" to "without parameter"

For .htaccess file, I am creating a 301 redirection for my new website:

I want this:

From http://www.website.com/php_file.php?target=value1 to http://www.website.com/NewPage/

AND

From http://www.website.com/php_file.php?target=value2 to http://www.website.com/OtherNewPage/

i was trying

Redirect 301 /php_file.php?target=value1 http://www.website.com/newpage/

But I'm getting this result:

http://www.website.com/?target=value1

Upvotes: 2

Views: 39

Answers (1)

Florian Lemaitre
Florian Lemaitre

Reputation: 5748

You might try this instead:

RewriteBase /
RewriteCond %{QUERY_STRING} ^target=value1$
RewriteRule ^php_file.php$ http://www.website.com/newpage/? [R=301,L]

RewriteCond %{QUERY_STRING} ^target=value2$
RewriteRule ^php_file.php$ http://www.website.com/OtherNewPage/? [R=301,L]

The Key here is to use ? at the end of your redirection to prevent old query string to be added.

Upvotes: 3

Related Questions