Forum Moderators: mack

Message Too Old, No Replies

Redirecting error pages

Redirecting error pages

         

Bostonimages

8:32 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



My website is being hosted by a company called 1and1.

There instructions for redirecting pages are to create files called:

error400.html
error403.html
error404.html
error500.html

and upload them.

I have recently been reading the Google section of this forum and I am very unclear about what the best way is to redirect pages. Apparently Google can penalize a site for doing it wrong.

For instance if someone types

[webmasterworld.com...]
Secondly without the www's (webmasterworld.com)

Both of those pages should end up landing on the same page. They don't on my site.

I hope this made sense. Can anyone shed some light?

C

mack

10:23 pm on Feb 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Redirecting for your error pages is very different from redirecting non www to www.

The redirection that is being offered by your host is simply for error handling. For example if a user tried to go to example.com/foo but the page doesn't exist the server will handle it as a 404 (page not found) all the server will do is send the user to your custom 404 page. On this page you can have links to your important areas, to try and convert the user who has not found the information he#she was looking for.

You can do the same for all other error types. This form of redirection will only handle lost users (users who encounter an error) and will not effect your site in any other way.

Mack.

Bostonimages

12:07 am on Feb 13, 2006 (gmt 0)

10+ Year Member



Thanks Mack!

So can anyyone tell me the steps in creating pages that redirect non www to www

is there a code i put at the top of the pages or do i create a special page like the error pages?

Bostonimages

1:18 pm on Feb 14, 2006 (gmt 0)

10+ Year Member



Does anyone have a website that they can refer me to get this accomplished?

jdMorgan

1:30 pm on Feb 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What kind of server are you hosted on - For example, IIS or Apache?

The methods for implementing proper server-side redirection depend on the server type.

We have extensive discussion of this subject here at WebmasterWorld in the Microsoft and Apache forums.

Jim

Bostonimages

8:01 pm on Mar 13, 2006 (gmt 0)

10+ Year Member



I think I'm on Linux?

Is that the same as Apache?

sensation

8:14 am on Mar 14, 2006 (gmt 0)

10+ Year Member



Look in your root directory via your FTP client for an .htaccess file. If you have one there edit it to look like this. Make sure you substitute ".yourdomainname" and "yourdomainname.com" for your "actual" domain name

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST}!^www\.yourdomainname\.com [NC]
RewriteRule ^(.*) [yourdomainname.com...] [L,R=301]

If you don't have an .htaccess file in your root directory, then open notepad and type that in there and save it as htaccess.txt or htaccess.htaccess and FTP into your root directory and upload the file. Once the file is there rename it .htaccess. Now when someone types in yourdomainname.com into their browser, they will be redirected to www.yourdomainname.com. This includes spiders as well. What happens is. without this rewrite on. Your page rank is split in half. That's the penalty the search engine dishes out to you.

HTH

Bostonimages

4:55 pm on Mar 14, 2006 (gmt 0)

10+ Year Member



Thanks sensation
Unfortunately something didn't work.

I didn't have a htaccess file so I copied the text as you sent it - changed it to my domain in two places.

Saved as a txt

uploaded

Changed to .htaccess

... Then the file immediately disappeared?

... Does that mean 1and1 doesn't allow .htaccess?

I checked online to see if it changed but no luck?

sensation

1:53 am on Mar 15, 2006 (gmt 0)

10+ Year Member



You need to make sure that you upload your .htaccess file in ASCII rather than binary format, to ensure that information in the file is not corrupted. Also you need to be aware that most FTP programs do not show hidden files by default, so if you upload a correctly named file then you may think that you hadn't uploaded it. Similarly, if you need to rename it on the server, the file may appear to disappear from view even when it is still there. So make sure you configure your FTP client to show hidden files.

Try putting the .htaccess file in your www directory. That would be the "public html" folder. See if it disappears from there. The reason I told you to put it in your root directory is because that way it will affect your whole site. It will work in the public html directory just fine as well.

HTH

sensation

2:29 am on Mar 15, 2006 (gmt 0)

10+ Year Member



You may want to write the .htaccess redirect this way.

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ [yoursite.com...]

If this or the other redirect doesn't do the job for you after you test it. You should remove it asap.

jdMorgan

5:40 am on Mar 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is a forum-induced typo in the first code snippet above. Both the first and the second code snippets are missing required spaces.

I'd recommend either:


Options +FollowSymLinks
RewriteEngine on
# If requested hostname is non-blank
RewriteCond %{HTTP_HOST} .
# and if requested hostname is not the preferred one
RewriteCond %{HTTP_HOST} !^www\.yourdomainname\.com
# Then redirect to preferred domain
RewriteRule (.*) http://www.yourdomainname.com/$1 [R=301,L]

-or-

Options +FollowSymLinks
RewriteEngine on
# If the requested hostname is the non-preferred one
RewriteCond %{HTTP_HOST} ^yourdomainname\.com [NC]
# then redirect to the preferred domain
RewriteRule (.*) http://www.yourdomainname.com/$1 [R=301,L]

If you have problems with the code, just upload a blank .htaccess file to 'erase' the one with the problem code in it. This will work whether the .htaccess file is visible or not.

Jim