+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Help setting up redirect for "not found" pages

  1. #1
    granger99 is offline x10Hosting Member granger99 is an unknown quantity at this point
    Join Date
    Dec 2009
    Posts
    33

    Help setting up redirect for "not found" pages

    I would like to have one redirect for all "not found" pages on my site. Ideally, any such pages would be redirected to the home page. Is this possible without knowing which pages they are? One way is in the .htaccess file, like this perhaps?

    RewriteEngine On

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

    RewriteRule \/.+ / [L,R]



    Or can I do it via cPanel somehow?

    Thanks for your help!

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Help setting up redirect for "not found" pages

    Maybe try...


    Code:
    RewriteCond %{REQUEST_FILENAME} !-f  
    RewriteCond %{REQUEST_FILENAME} !-d  
    RewriteRule .* /index.html  [L]
    if the homepage is index.html (adjust to your case)
    Nothing is always absolutely so.

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Help setting up redirect for "not found" pages

    You could also set a script as the error handler using ErrorDocument, and have that script redirect. You could even set the index page as the error document. However, I recommend against redirecting without some sort of not-found notice. It breaks people's expectations and doesn't play well with old links and bookmarks. Better to have a custom error page that includes links to the main page and to pages with similar URLs (which can be tricky to implement).
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    granger99 is offline x10Hosting Member granger99 is an unknown quantity at this point
    Join Date
    Dec 2009
    Posts
    33

    Re: Help setting up redirect for "not found" pages

    Thanks for the replies - basically I have heard that the search engines don't like 404 errors, and so it's best to change all not found pages to 301 or 302 redirects.

    My purpose is less for the reader and more for the purpose of keeping the search engines happy by having as few error pages as possible.

    With that in mind, would you still make the same recommendations?

    Thank you again for trying to help me.

  5. #5
    vishal's Avatar
    vishal is offline -::-X10 Guru-::- vishal has a brilliant futurevishal has a brilliant future
    Join Date
    Nov 2009
    Location
    INDIA
    Posts
    5,254

    Re: Help setting up redirect for "not found" pages

    good recommendation ,
    Regards ~ Vishal
    Giving Reputation (at bottom of my post ) is the best way to encourage the person who helped you on forums.

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Help setting up redirect for "not found" pages

    Quote Originally Posted by granger99 View Post
    Thanks for the replies - basically I have heard that the search engines don't like 404 errors, and so it's best to change all not found pages to 301 or 302 redirects.
    What, exactly, did the source(s) say the problem was? A 404 means no resource exists at the given URL. If the URL used to be valid but isn't any longer, a 301 is appropriate (but ask yourself: why did the URL change? As the W3C says, "Cool URIs don't change"). If a URL doesn't name something on the site, a 404 is the most appropriate response. The only inappropriate response you commonly see is returning a 200 for an error page. If a non-existent URL results in a redirect to the home (or other prominent) page, the search engine might mark you down for duplicate content.

    A search engine will only come across a 404 when following a dead link or a typo. In both cases, your log should reveal the referrer URL that contains the bad link, letting you contact the site to correct it.

    Quote Originally Posted by granger99 View Post
    With that in mind, would you still make the same recommendations?
    Yes. Keep the 404s with well-designed error pages. There are countless pages that discuss this topic. Let Google be your guide.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  7. #7
    granger99 is offline x10Hosting Member granger99 is an unknown quantity at this point
    Join Date
    Dec 2009
    Posts
    33

    Re: Help setting up redirect for "not found" pages

    The reason my URL's have changed is because I changed them! Specifically, I changed the command in wordpress to /%postname%/ which made all of the previous URL's invalid. Therefore, for any pages Google has already indexed (my blog is still quite young), I want to make sure a 404 error doesn't occur.

    Is there a silver bullet here? For example, change a line or two in the htaccess and all of these old URL's end up on my home page?

  8. #8
    slacker3 is offline x10 Sophmore slacker3 is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    146

    Re: Help setting up redirect for "not found" pages

    Quote Originally Posted by granger99 View Post
    The reason my URL's have changed is because I changed them! Specifically, I changed the command in wordpress to /%postname%/ which made all of the previous URL's invalid. Therefore, for any pages Google has already indexed (my blog is still quite young), I want to make sure a 404 error doesn't occur.

    Is there a silver bullet here? For example, change a line or two in the htaccess and all of these old URL's end up on my home page?

    as google says:
    Google updates its entire index regularly. When we crawl the web, we automatically find new pages, remove outdated links, and reflect updates to existing pages, keeping the Google index fresh and as up-to-date as possible.
    If outdated pages from your site appear in the search results, ensure that the pages return a status of either 404 (not found) or 410 (gone) in the header. These status codes tell Googlebot that the requested URL isn't valid. Some servers are misconfigured to return a status of 200 (Successful) for pages that don't exist, which tells Googlebot that the requested URLs are valid and should be indexed. If a page returns a true 404 error via the HTTP headers, anyone can remove it from the Google index using the URL removal tool. Outdated pages that don't return true 404 errors usually fall out of our index naturally when other pages stop linking to them.

    http://www.google.com/support/webmas...&answer=156412

    http://www.google.com/support/webmas...n&answer=92865

    http://labnol.blogspot.com/2005/09/c...elete-404.html

    EDIT:
    my suggestion would be to register at google webmaster tools to make an url removal request (shouldn't be necessary, tough) and/or create an custom 404 page and redirect with javascript to the main page (or some other desired page..)

    google won't follow javascript redirects (as far as i know)
    Last edited by slacker3; 01-12-2010 at 03:41 PM. Reason: ...

  9. #9
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Help setting up redirect for "not found" pages

    Quote Originally Posted by granger99 View Post
    The reason my URL's have changed is because I changed them!
    But why did you need to change them?

    In this case, you should redirect the old URLs to the new ones so they can be found, rather than redirecting them all to the home page. You can use the rewrite engine or RedirectMatch, which is tailored for redirects.
    Last edited by misson; 01-12-2010 at 04:38 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  10. #10
    granger99 is offline x10Hosting Member granger99 is an unknown quantity at this point
    Join Date
    Dec 2009
    Posts
    33

    Re: Help setting up redirect for "not found" pages

    Thank you very much, I will spend some time digesting your suggestions and then get back to you. I really appreciate your help!

    Just one more question for now - I realize that you don't approve of me sending all redirects to my home page, but if I truly want to do it that way, is it possible? What would be the code in my htaccess necessary to achieve that?
    Last edited by granger99; 01-12-2010 at 06:11 PM. Reason: added text

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Redirect all 404 pages to index.html
    By ultimatebuster in forum Free Hosting
    Replies: 3
    Last Post: 07-24-2009, 02:42 PM
  2. Can i redirect pages automatically?
    By tlife143 in forum Programming Help
    Replies: 12
    Last Post: 07-14-2009, 10:39 AM
  3. Replies: 7
    Last Post: 09-16-2005, 10:27 AM
  4. trouble with setting up web pages
    By gnarkill in forum Scripts & 3rd Party Apps
    Replies: 4
    Last Post: 07-12-2005, 09:54 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers