Setting Up 301 Redirects

TheBigK

Well-known member
As most of you can guess, I'm into the desperation mode to fix the 404 errors on my site. I've asked this questions at several places but XF seems to be the only place where I get reliable answers. I'd really appreciate help on setting up 301 redirects for the large number of tags that I deleted from my 'wordpress' blog.

I want to setup a 301 redirect to the homepage only for the deleted tags from domain.com/tag/<deleted.tag> => domain.com. I want to keep the regular 404 pages though for other locations that are 'not found'.

I'm not sure whether I should add it to .htaccess or setup a function in wordpress (if yes, what'd be the location of the file that I need to edit?)
 
Nice one Jake.

I actually fixed this for BigK the other day.

WordPress forwards you to a theme specific 404.php page when a page is not found.

e.g. http://www.crazyengineers.com/jakeistheman

I amended the 404.php file to include this:

PHP:
if (strstr($_SERVER['REQUEST_URI'], '/tag/'))
{
	header("HTTP/1.1 301 Moved Permanently");
	header("Location: ".get_bloginfo('url'));
 
	exit();
}

Therefore, now any 404 page containing /tag/ will be 301 redirected to the site home page, e.g. http://www.crazyengineers.com/tag/jakeistheman whereas any other 404 is dealt with normally.
 
Looks like my 404 errors aren't going away. I found out that after uninstalling the 'events' add-on (Xenatendo) - there are a large number of 404 pages for all the calendar entries. What would be the rule to divert all best way to turn domain.com/community/events/ to domain.com/community/ ? (301 redirects).

Also, which htaccess file should I edit (the one under main domain or the one under /community/ ? )
 
Looks like my 404 errors aren't going away. I found out that after uninstalling the 'events' add-on (Xenatendo) - there are a large number of 404 pages for all the calendar entries. What would be the rule to divert all best way to turn domain.com/community/events/ to domain.com/community/ ? (301 redirects).

Also, which htaccess file should I edit (the one under main domain or the one under /community/ ? )

Add to .htaccess in /community directory:

Rich (BB code):
#	Mod_security can interfere with uploading of content such as attachments. If you
#	cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#	SecFilterEngine Off
#	SecFilterScanPOST Off
#</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 500 default

<IfModule mod_rewrite.c>
	RewriteEngine On

	RewriteRule ^events/.*$ http://www.yoursite.com/community/? [R=301,L]

	#	If you are having problems with the rewrite rules, remove the "#" from the
	#	line that begins "RewriteBase" below. You will also have to change the path
	#	of the rewrite to reflect the path to your XenForo installation.
	#RewriteBase /xenforo

	#	This line may be needed to enable WebDAV editing with PHP as a CGI.
	#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

	RewriteCond %{REQUEST_FILENAME} -f [OR]
	RewriteCond %{REQUEST_FILENAME} -l [OR]
	RewriteCond %{REQUEST_FILENAME} -d
	RewriteRule ^.*$ - [NC,L]
	RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
	RewriteRule ^.*$ index.php [NC,L]
</IfModule>

IMO this isn't a problem to begin with. 404 means the page no longer exists which is expected because you removed it. Not sure how that's a problem.
 
Thank you, Jake. My concern at the moment is to make sure that the Google Webmaster Tools shows < 2k 'Page Not Found' errors. Currently it's at 96k page not found errors which is down by 3k after I fixed the broken tags on my wordpress installation. I've arrived at a conclusion that the page not found errors are causing the site rankings to go down, despite google's post that said 404s don't affect page rankings.
 
If a 404 lowers rank (which it shouldn't) then I'm not sure how a 301 would help. You are saving none of the original content in this case.
 
If a 404 lowers rank (which it shouldn't) then I'm not sure how a 301 would help. You are saving none of the original content in this case.
Well, I'm not sure if I'm doing the right thing. Google reported traffic going down just at the same time it reported large 404 errors. I've searched around and found a few people saying the same: large number of 404 errors causing SERPs to go down.

Google takes lot of time to drop 404s from their index and I can't afford to lose our traffic for that long. Is there any other way to deal with the situation?
 
I don't know. But you are redirecting people away from a page that no longer exists to a page that isn't what they wanted. I think the 404 is more useful to the end user.

When you delete content you should expect to lose that traffic, no?
 
I would also confirm that too many 404's is not good but I wouldn't suggest to add 301 for URL that doesn't exist. We had tried that before and outcome wasn't good. Google will think you have hundreds of link for similar content.. and end result wouldn't be too good. But then again this happened to my friend who was using vB 3.8.x series.

Google will slowly delete those pages. It would take time but it wouldn't be to long. If you have extra resources on your machine increase your crawl rate to speed up the process.
 
I don't know. But you are redirecting people away from a page that no longer exists to a page that isn't what they wanted. I think the 404 is more useful to the end user.

When you delete content you should expect to lose that traffic, no?
I found out the issue - and it was with the 'Disqus' plugin we used on Wordpress. Several other webmasters have had the same issue and I've resolved most of them. Few URLs that I wish to redirect are really old ones and I'd really appreciate if you could comment whether the .htaccess rule would be written as follows -

Code:
Redirect 301 /old-path-linked-by-another-website /correct-path-on-my-site

Do I need to write 'ReadWriteEngineOn' before I write that (if it's already written at the top of the .htaccess file)?

I've about 15 such distinct URLs that I need to their correct locations.
 
No. Those Redirect commands don't require you to enable the RewriteEngine.
Thanks, is the syntax correct? Should I make a list of the URLs that need to be redirected viz -

Redirect 301 /incorrect-url-linked /correct-url-on-site/
Redirect 301 /another-url/ /correct-url/
..
.... and so on?
 
Nice one Jake.
I amended the 404.php file to include this:

PHP:
if (strstr($_SERVER['REQUEST_URI'], '/tag/'))
{
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: ".get_bloginfo('url'));
 
    exit();
}
.
I have a lot of 404 errors due to deleted users (e.g. /member/1234 ) and would like to do sth similar. If a link to a profile page causes an 404 error I would like to redirect (301) this profile page.

Any ideas how I could do this with XF1.5. @Chris D ?
 
I've somewhat changed my outlook on such things over the years.

It's frankly not worth the effort. People have this impression that they couldn't possibly ever return a 404 because instantly Google will start penalising you. This is far from the case.

Google Webmaster Tools and such notify you of 404s in an advisory sort of fashion merely to highlight any potential mistakes. For example, if all of a sudden ALL of your members pages started returning 404 then that'd be some sort of fault that needs resolving. However, if you have comparatively small number of URLs returning a 404, this is normal and basically expected in the grand scheme of things, and returning a 404 is a perfectly normal thing to do when content is not found.

When Google hits a 404 and that status is maintained for some time, it will just trigger them to remove that entry from its index eventually so the "problem" actually solves itself automatically.

Coupled with an automatically submitted Sitemap, this is more than sufficient and won't require you to take any further action.

Clearly if we thought that returning a 301 redirect rather than a 404 was more beneficial, the software would already do that :)
 
Back
Top Bottom