Question

I am attempting to add in a 301 to an old script of mine, but when I add the 301 I expect the old URL to be redirected to

http://www.newwebsite.co.uk/new-product.html

But instead I get

http://www.newwebsite.co.uk/new-product.html?id=old-product.html

What is wrong?

Below is my htaccess file, you can see the 301 I have added to this existing code near the top.

Options +FollowSymlinks

RewriteEngine On

Redirect 301 /old-product.html http://www.newwebsite.co.uk/new-product.html

RewriteCond %{HTTP_HOST} ^websiteone\.co.uk$
RewriteRule ^(.*) http://www.websiteone.co.uk/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^websitetwo\.co.uk$
RewriteRule ^(.*) http://www.websitetwo.co.uk/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^websitethree\.co.uk$
RewriteRule ^(.*) http://www.websitethree.co.uk/$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|less|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]

ErrorDocument 404 /notfound.php

#RewriteRule contents/(.*)/(.*)$                            page.php?page_id=$1&url=$2  [NC,L,QSA]

RewriteRule login.html                                          account.php     [NC,L,QSA]

RewriteRule registration.html                               registration.php            [NC,L,QSA]

RewriteRule payment-success.html                        success.php     [NC,L,QSA]

RewriteRule forgotpassword.html                         accountforgotpass.php   [NC,L,QSA]

RewriteRule myprofile.html                                  accountloggedin.php     [NC,L,QSA]

RewriteRule editprofile.html                                accounteditdetails.php  [NC,L,QSA]

RewriteRule shopping-cart.html                          cart.php    [NC,L,QSA]

RewriteRule payment-checkout.html                       checkout.php    [NC,L,QSA]

RewriteRule checkout-password.html                checkoutenterpass.php [NC,L,QSA]

RewriteRule checkout-detail.html                    checkout2.php   [NC,L,QSA]

RewriteRule reset/(.*)/$                                    password_reset.php?vcode=$1 [NC,L,QSA]

RewriteRule (.*)$                                                       include_file.php?id=$1 [NC,L,QSA]    
Was it helpful?

Solution

Your redirect is done by your Redirect line;

Redirect 301 /old-product.html http://www.newwebsite.co.uk/new-product.html

...but the file will go on processing. The last RewriteRule...

RewriteRule (.*)$   include_file.php?id=$1 [NC,L,QSA]

...will also catch the same URL and rewrite it.

What you probably want to do is to replace the Redirect directive with a regular RewriteRule;

RewriteCond %{REQUEST_URI} ^/old-product.html [NC]
RewriteRule ^ http://www.newwebsite.co.uk/new-product.html [R=301,L]

...which will redirect to the new URL and use the L flag to avoid processing the rest of the file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top