Log in

View Full Version : 301 redirect via htaccess help please



gwmbox
05-16-2016, 01:19 AM
I have been trying to figure out what I have been doing wrong with my 301 redirects but I am not getting the results required (this is a WordPress web site).

We have made changes to our site by removing certain sections and now just want to point those old URL's to a replacement

for example

OLD: /art-prints-gifts-and-decor/zazzle-gift-shop/accessories/bags/
NEW: /portfolio-shop/

via using

redirect 301 /art-prints-gifts-and-decor/zazzle-gift-shop/accessories/bags/ /portfolio-shop/

however when i visit the old URL it redirects to /portfolio-shop/bags/

(why is it adding bags/?

How can I fix this please.

GW

Beverleyh
05-16-2016, 05:09 AM
Shouldn't the syntax be

Redirect 301 /art-prints-gifts-and-decor/zazzle-gift-shop/accessories/bags/ http://mywebsite.com/portfolio-shop/
?

gwmbox
05-16-2016, 05:42 AM
But it is the same web site, just a change of some url's or, as above, a complete removal of some no longer active urls, so I want to redirect to a page (as set) instead of just a 404 message.

EDIT: HMM - it appears you are right would not have thought that would make such a difference - but thanks as it is working now

EDIT 2 - Nope that did not change it. the same applies as per my first post

EDIT 3 - This is a https secure site as well if that makes a difference.

gwmbox
05-16-2016, 05:54 AM
Stupid thing works fro some and not others.

At least I know I have the right syntax now though :)

jscheuer1
05-17-2016, 04:08 AM
Just as a note here, I did a quick search and all of the examples I saw used the full URL for the redirected TO page. So you gotta think that's important. Perhaps, and especially if it's https, you might want to do two or more redirects. One from the https partition and one from the http one. Other possible FROM addresses would be the https://www and the https:// without the www and likewise for the http versions of those. Basically, what I'm saying is that it cannot hurt to cover all possible bases with the FROM address(es) and of course make them all redirect to the same desired TO address. One per line, each with the desired TO address on the right in the .htaccess file.

Beverleyh
05-17-2016, 05:48 AM
Additional, just in case it *is* an issue, if you *do* have both http:// and http://www versions of the same url able to resolve, it will be better for SEO to pick only one and globally redirect to that. Allowing the use of both variations can really mess with your analytics and dilute link-juice.

To fix that, you can redirect to www versions like this;

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

or non-www versions like this;


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


Whichever you choose should go before any individual 301 redirects, and immediately after RewriteEngine On

Pick which you prefer but you might need to check exact syntax with your web host - they could have their own recommendations in their FAQs

This method will cut out the need for duplicate individual www or non-www 301 redirect lines (this is a global redirect)

gwmbox
05-17-2016, 06:46 AM
Thanks guys, I had the with or without www working ok as well as from http to https. Now with adding the full url to the second part (new url) it seems to be working as best it can :)

Thanks again for your help