How to do 301 redirect with Dynamic URL and keep some value to new url

79 views Asked by At

I have a problem to do 301 redirect with Dynamic URL. I want to redirect any URL that have "pageId=xxxxxxxxx" to a new URL that append with "pageId=xxxxxxxxx" in the end of new URL.

For Example, An old url is

abc.co.uk/level1/level2/knife/page/190011770?temp=submitview&pageId=190011770&layout=1column

to new URL:

abc.co.uk/review?pageId=190011770

I try to write a redirection rule like these 2 rule:

RewriteRule ^pageId=(.*)$ http://abc.co.uk/review?pageId=$1 [R=301,L]

and

RewriteCond %{QUERY_STRING} ^pageId=[0-9]*$
RewriteRule ^(.*)$ http://abc.co.uk/review?pageId=$1? [L,R=301]

but both of them are not work. I got HTTP code 200 instead 301

Please help me.

1

There are 1 answers

0
Jon Lin On

To ensure that you don't have redirect loops, you have to make sure the URI isn't already "review":

RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)pageId=([0-9]+)(&|$)  
RewriteRule ^(?!review)(.*) /review?pageId=%2 [NC,R,L]