Welcome to WebmasterWorld Guest from 50.17.16.177

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

301 redirect best practice

     
1:12 pm on Sep 6, 2012 (gmt 0)

Full Member

5+ Year Member

joined:Oct 11, 2010
posts: 226
votes: 0


Hi Guys Implemented a 301 a few months ago (14 weeks to be precise), i have rankings that have dived and not recovered, The original 301 was implemnted by PHP but a few weeks ago i have asked my developer to change this to htaccess which now 50% is done via the old site attempting to do the new site once we confirmed all is best practice

Scenario is

www.example.net was renamed to www.example.com

Both sites sit on different servers along with different I.P's

the new sites 301 is currently handled by php and although we get all the correct headers and such i believe there to be an issue as rankings are still 80% down, this php handles the canonicals and removes the forward slash pretty simple

As i mentioned we are going to implement a htaccess version on both servers

On the old we are going to add the below which is a simple redirect

RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

we were advised to add the below, but we got an internal 500 server error however the single line code works just fine, however there must be a reason for the below and is it best practice...

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.net$
RewriteRule (.*)$ http://www.example.com/$1 [R=301,L]


On the new server which is currently being handle by PHP I have sought help already a month or 2 ago but wanted to check that what i was doing was correct and no unwanted chaining being forced, so not implemented yet it will be in the next few days once i get my head around what's exactly needed

On the new server were going to add this which should deal with Canonicals, removal of upper case urls along with, removal of the forward slash

# 31 - Redirect index requests on new server
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index(\.(php|html?))?
RewriteRule ^(([^/]+/)*)index(\.(php|html?))?$ http://www.example.com/$1? [R=301,L]

# 32 - Redirect .php requests to extensionless URL
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*[^/.]+)\.php
RewriteRule ^(([^/]+/)*[^/.]+)\.php$ http://www.example.com/$1? [R=301,L]

# 33 - Redirect non-canonical requests to www
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

would the above be best practice when doing a website name chnage

Thank you
9:39 am on Sept 13, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


The Condition is needed on each rule that you want it apply to.
11:00 am on Sept 13, 2012 (gmt 0)

Full Member

5+ Year Member

joined:Oct 11, 2010
posts: 226
votes: 0


I Have added RewriteCond %{REQUEST_URI} !^/run\.php

to rule # - 32

Really sorry with all my requests for information i am trying to learn and have taken a lot on board


RewriteEngine on

# 2 Redirect Individual renamed pages

RewriteRule ^oldpage1$ http://www.example.com/test/newpage1? [R=301,L]
RewriteRule ^oldpage2$ http://www.example.com/test/newpage2? [R=301,L]
RewriteRule ^oldpage3$ http://www.example.com/test/newpage3? [R=301,L]
RewriteRule ^oldpage4$ http://www.example.com/test/newpage4? [R=301,L]
RewriteRule ^oldpage5$ http://www.example.com/test/newpage5? [R=301,L]
RewriteRule ^oldpage6$ http://www.example.com/test/newpage6? [R=301,L]
RewriteRule ^oldpage7$ http://www.example.com/test/newpage7? [R=301,L]
RewriteRule ^oldpage8$ http://www.example.com/test/newpage8? [R=301,L]
RewriteRule ^oldpage9$ http://www.example.com/test/newpage9? [R=301,L]
RewriteRule ^oldpage10$ http://www.example.com/test/newpage10? [R=301,L]
RewriteRule ^oldpage11$ http://www.example.com/test/newpage11? [R=301,L]


# 31 - Redirect index requests on new server
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index(\.(php|html?))?
RewriteRule ^(([^/]+/)*)index(\.(php|html?))?$ http://www.example.com/$1? [R=301,L]

# 32 - Redirect .php requests to extensionless URL
RewriteCond %{REQUEST_URI} !^/run\.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*[^/.]+)\.php
RewriteRule ^(([^/]+/)*[^/.]+)\.php$ http://www.example.com/$1? [R=301,L]

# 33 - Redirect non-canonical requests to www
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
3:08 pm on Sept 13, 2012 (gmt 0)

Full Member

5+ Year Member

joined:Oct 11, 2010
posts: 226
votes: 0


Answered my own question it does work however i have noticed that the removal of the forward stroke works on the home page as does the upper and lower cases anything after the first trailing slash does not,

so www.example.com perfect anything in the next directory level does not www.example.com/mysite

RewriteEngine on

# 2 Redirect Individual renamed pages

RewriteRule ^oldpage1$ http://www.example.com/test/newpage1? [R=301,L]
RewriteRule ^oldpage2$ http://www.example.com/test/newpage2? [R=301,L]
RewriteRule ^oldpage3$ http://www.example.com/test/newpage3? [R=301,L]
RewriteRule ^oldpage4$ http://www.example.com/test/newpage4? [R=301,L]
RewriteRule ^oldpage5$ http://www.example.com/test/newpage5? [R=301,L]
RewriteRule ^oldpage6$ http://www.example.com/test/newpage6? [R=301,L]
RewriteRule ^oldpage7$ http://www.example.com/test/newpage7? [R=301,L]
RewriteRule ^oldpage8$ http://www.example.com/test/newpage8? [R=301,L]
RewriteRule ^oldpage9$ http://www.example.com/test/newpage9? [R=301,L]
RewriteRule ^oldpage10$ http://www.example.com/test/newpage10? [R=301,L]
RewriteRule ^oldpage11$ http://www.example.com/test/newpage11? [R=301,L]


# 31 - Redirect index requests on new server
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index(\.(php|html?))?
RewriteRule ^(([^/]+/)*)index(\.(php|html?))?$ http://www.example.com/$1? [R=301,L]

# 32 - Redirect .php requests to extensionless URL
RewriteCond %{REQUEST_URI} !^/run\.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*[^/.]+)\.php
RewriteRule ^(([^/]+/)*[^/.]+)\.php$ http://www.example.com/$1? [R=301,L]

# 33 - Redirect non-canonical requests to www
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
8:58 pm on Sept 13, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12709
votes: 244


as does the upper and lower cases anything after the first trailing slash does not

Right. The domain name is case-insensitive (you can amuse yourself by looking up random domains at DomainTools or similar and see their wild & wonderful best guesses at intended casing :)); the rest of the URL is case-sensitive. Technically it depends on the server, but you should always treat it as case sensitive. Regular Expressions as used in Apache are case sensitive unless you expressly tell them not to be.
9:35 pm on Sept 13, 2012 (gmt 0)

Full Member

5+ Year Member

joined:Oct 11, 2010
posts: 226
votes: 0


Hi Lucy24

Kind of Lost me, I think i done well getting this far, i really wish i fully understood as i marvel sometimes at what some developers and coders can do, if it were my main job and worked on this all the time im positive i would have a much better grasp on the whole process.. the code now is too complex for me to work out and i don't want to guess as its been 14 weeks for me without traffic and im blaming the old PHP redirect and wanted this Htaccess to replace what the PHP did just so as i can rule out any human error.

If you could point me in the right direction of what would i should search for im sure i can find an example and implement and post back for confirmation, but im scared of just adding something which if im honest is a little out of my remit and i dont fully understand
3:06 pm on Sept 14, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 7, 2003
posts:4783
votes: 0


stuff like:
RewriteRule ^oldpage1$ http://www.example.com/test/newpage1? [R=301,L]

can also -easier IMHO- be written as:
RedirectPermanent /oldpage1.html http://www.example.com/test/newpage1

or
RedirectPermanent /oldpage1.html http://www.example.com/test/newdir1/

RedirectPermanent /olddir1/ http://www.example.com/test/newdir1/


I guess I started using this long before apache had rewriterules :-)
Considering the capabilities for complex things rewriterules can handle, I'd still prefer the old Redirect (302) or RedirectPermanent (301) just for efficiency till I'd seen performance figures indicating otherwise.
9:50 pm on Sept 14, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12709
votes: 244


Heh, you've missed several years on mod_alias ("redirect" by that name) vs mod_rewrite discussion. Using mod_alias is obviously easier and in fact it's what Apache recommends. BUT they seem to work on the assumption that you're doing this in the config file of your own server. If you're in htaccess, you have no control over which module executes first-- that is, whether your Redirects come before or after your RewriteRules. It doesn't matter how you arrange the htaccess; each module executes as a package.

Doing everything with mod_rewrite means you can be sure things will happen in the right order, because within any one module your commands will execute in the order you put them.
6:40 am on Sept 15, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0



301 redirects generated by Redirect, RedirectMatch, RewriteRule or a HEADER directive in PHP all look exactly the same to the browser that made the original request.

It's the module execution order and rule execution order that are crucial here, so you would want to use directives from only one module. So, mod_Alias (Redirect, RedirectMatch) can only do redirects while mod_Rewrite (RewriteRule) can do redirects or rewrites. As soon as you have a single RewriteRule it's time to convert all of your Redirect and RedirectMatch code to instead use RewriteRule.
11:31 am on Sept 15, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12709
votes: 244


g1 sets a new record for time elapsed between opening a tab and posting reply to most recent visible post. "Dang! Could swear I answered this already!" ;)
4:13 pm on Sept 15, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


I answered 6 hours before but with a silly typo which I didn't spot for 6 hours, so I reposted and a kindly mod zapped the obviously redundant copy some time later. :)
9:52 pm on Sept 17, 2012 (gmt 0)

Full Member

5+ Year Member

joined:Oct 11, 2010
posts: 226
votes: 0


Hi Guys

Reading an old thread on here in regard to best practice and although 2007 has much changed. [webmasterworld.com ]

For instance is it too late for me to say rather than a site wide redirect i could redirect my top 100 pages and then let the rest go 404 or is 14 weeks into a change too late

I really wish i could start this again as after all the reading and such there do seem to be safer options
11:39 pm on Sept 17, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


You can alter it, but it might take Google some 3 to 6 months more to pick up those changes.
1:36 am on Sept 18, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12709
votes: 244


Are you currently redirecting or going straight to 404/410? If you pull selected pages out of the 410 bin and start redirecting them, the first thing you will notice is Googlebot running around asking for all those other pages again, including the one's you'd thought it had finally managed to forget. Obviously it's checking to see whether any of the others is suddenly getting a fresh redirect.

Ask how I know this. Ugh. Big mess.
6:18 am on Sept 18, 2012 (gmt 0)

Full Member

5+ Year Member

joined:Oct 11, 2010
posts: 226
votes: 0


Are you currently redirecting or going straight to 404/410?


Im redirecting everything after a name change, redirect went perfect, however 14 weeks in and rankings are very very slowly climbing, im still around 70% down from where i previously was

its like Google has not seen what i have done as a 301 , its more like its moved the pages and seen it as a 302, hence why i changed my original PHP redirect to a Htaccess just in case there was something a miss somewhere

I may just be unlucky and will have to wait a few more weeks / months for Google to push all the old juice over from the old site
6:29 am on Sept 18, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10543
votes: 8


Im redirecting everything after a name change

have you checked your GWT account(s) for the old hostname(s) recently?
i wonder if google is seeing a lot of "soft 404s"
7:39 am on Sept 18, 2012 (gmt 0)

Full Member

5+ Year Member

joined:Oct 11, 2010
posts: 226
votes: 0


Hi phranque

Just checked those and no, theres no soft 404's there at all

All the 404's i see are what i would expect to see
7:49 am on Sept 18, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12709
votes: 244


All the 404's i see are what i would expect to see

Soft 404s will not be listed among the 404s. That's what "soft 404" means.
8:22 am on Sept 18, 2012 (gmt 0)

Full Member

5+ Year Member

joined:Oct 11, 2010
posts: 226
votes: 0


yeah did check all errors and no soft 404's at all
8:38 am on Sept 18, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10543
votes: 8


there have been many posts recently about the accuracy and currency of GWT data so I woulld keep an eye on the soft 404s to see if they are reported later.
8:53 am on Sept 18, 2012 (gmt 0)

Full Member

5+ Year Member

joined:Oct 11, 2010
posts: 226
votes: 0


Its been 14 weeks, I would have thought that if there was anything obvious it would have reared its ugly head by now, however i only implemented the new htaccess file just over a week ago so plenty of time to wait

Looks like mine is going to go down to the wire and take the maximum it possibly can as that's my luck.

I was thinking of adding some individual rules to my htaccess to try and force maybe the home page and maybe 1 or 2 of the others but will probably cause more harm than good
This 50 message thread spans 2 pages: 50
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members