Reputation: 2650
Recently I changed some articles in my site from one category to another and now I want to put redirect in htaccess so when user find it the previous address in search engine then redirect to new address:
example.com/sport/spdetails.php?articleid=28984&parentid=184&catid=184
redirect to:
example.com/sport/spdetails.php?articleid=anynumber&parentid=184&catid=189
Upvotes: 1
Views: 43
Reputation: 45829
Try something like the following near the top of your .htaccess
file, using mod_rewrite:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^articleid=(\d+)&parentid=184&catid=184$
RewriteRule ^sport/spdetails\.php$ /sport/spdetails\.php?articleid=%1&parentid=184&catid=189 [R,L]
%1
is a backreference to the captured pattern (articleid value) in the last matched CondPattern, ie. the query string.
This is a temporary (302) redirect. Change it to R=301
(permanent) only when you are sure it's working OK.
UPDATE:
I have 50 articles that i want redirect its url with catid from 184 to 189 but with one line code in htaccess
Assuming you want to redirect these to the same catid
, ie 189
(as in your question), then you can change the RewriteCond
directive to read:
RewriteCond %{QUERY_STRING} ^articleid=(\d+)&parentid=184&catid=18[4-9]$
Upvotes: 1