Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: How to Direct all 404's to Main Page?

  1. #1
    iowadawg's Avatar
    iowadawg is offline Free Cell Champion
    Join Date
    May 2010
    Location
    Not in Texas
    Posts
    2,148
    Blog Entries
    4
    Thanks
    171
    Thanked 365 Times in 314 Posts

    How to Direct all 404's to Main Page?

    OKay, what is the best what to redirect to the main page of a blog (or even a particular page) when people put in weird words or whatever at the end of the domain?

    For example, looking at stats of one blog, scads of people (for whatever reason) are coming to my blog using:
    blogname.com/content/images/hernude.jpg (must have on one blog about 500 hits using different names).
    Or:
    blogname.com/submit.php, blogname.com/contact.php and so forth.

    I want it so anyone putting any invalid words after blogname.com will instead go straight to the main page.

    Thank you.

  2. #2
    Will.Spencer's Avatar
    Will.Spencer is offline Retired
    Join Date
    Dec 2008
    Posts
    5,033
    Blog Entries
    1
    Thanks
    1,010
    Thanked 2,329 Times in 1,259 Posts
    The easy way to do this is with an ErrorDocument statement in your .htaccess file.

    Example:
    ErrorDocument 404 /
    Submit Your Webmaster Related Sites to the NB Directory
    I swear, by my life and my love of it, that I will never live for the sake of another man, nor ask another man to live for mine.

  3. #3
    iowadawg's Avatar
    iowadawg is offline Free Cell Champion
    Join Date
    May 2010
    Location
    Not in Texas
    Posts
    2,148
    Blog Entries
    4
    Thanks
    171
    Thanked 365 Times in 314 Posts
    OKay, that is the geeky, long explanation for techical people that is of no use to me.

  4. #4
    Will.Spencer's Avatar
    Will.Spencer is offline Retired
    Join Date
    Dec 2008
    Posts
    5,033
    Blog Entries
    1
    Thanks
    1,010
    Thanked 2,329 Times in 1,259 Posts
    Just put a line that says "ErrorDocument 404 /" in your .htaccess file. Easy.
    Submit Your Webmaster Related Sites to the NB Directory
    I swear, by my life and my love of it, that I will never live for the sake of another man, nor ask another man to live for mine.

  5. #5
    iowadawg's Avatar
    iowadawg is offline Free Cell Champion
    Join Date
    May 2010
    Location
    Not in Texas
    Posts
    2,148
    Blog Entries
    4
    Thanks
    171
    Thanked 365 Times in 314 Posts
    Nope, does not work for a wordpress blog.
    Still shows error page.

  6. #6
    iowadawg's Avatar
    iowadawg is offline Free Cell Champion
    Join Date
    May 2010
    Location
    Not in Texas
    Posts
    2,148
    Blog Entries
    4
    Thanks
    171
    Thanked 365 Times in 314 Posts
    I do believe finally, after trying all kinds of .htaccess codes, and codes to add to 404.php pages, etc.
    I have found the fix for wordpress blogs!
    On the theme 404.php, replace it with the following code:

    <?php
    //Simple Redirect for WordPress.
    //Christopher Carey
    //301 Redirect for Wordpress
    //http://wwww.xrmo.com

    header("HTTP/1.1 301 Moved Permanently");
    header("Location: ".get_bloginfo('url'));
    exit();
    ?>

    Try it and see if it works for you when you go to my blog. Put whatever you want after the .com/
    Like: xrmo.com/whattheheck

    Thanks for your help.

  7. Thanked by:

    Aziz (10 October, 2010)

  8. #7
    Will.Spencer's Avatar
    Will.Spencer is offline Retired
    Join Date
    Dec 2008
    Posts
    5,033
    Blog Entries
    1
    Thanks
    1,010
    Thanked 2,329 Times in 1,259 Posts
    I'm glad that solution is working for you!

    One note: It's returning a 301 (moved) code instead of a 404 (not found) code.
    Submit Your Webmaster Related Sites to the NB Directory
    I swear, by my life and my love of it, that I will never live for the sake of another man, nor ask another man to live for mine.

  9. #8
    iowadawg's Avatar
    iowadawg is offline Free Cell Champion
    Join Date
    May 2010
    Location
    Not in Texas
    Posts
    2,148
    Blog Entries
    4
    Thanks
    171
    Thanked 365 Times in 314 Posts
    But it does take you to the main page right?

    The whole idea for me is simple.
    So many people search for weird items on one of my blogs.
    Like:
    /images/jessicaalbanude.jpg
    and so forth.
    I do not and have never had all those pictures that people are searching for on this blog.
    Thus now, instead of a 404 error page and they just leave the blog, now they go straight to the main page.
    Hopefully then they stick around and read my posts.

  10. #9
    Will.Spencer's Avatar
    Will.Spencer is offline Retired
    Join Date
    Dec 2008
    Posts
    5,033
    Blog Entries
    1
    Thanks
    1,010
    Thanked 2,329 Times in 1,259 Posts
    Quote Originally Posted by iowadawg View Post
    But it does take you to the main page right?
    It seems to work!
    Submit Your Webmaster Related Sites to the NB Directory
    I swear, by my life and my love of it, that I will never live for the sake of another man, nor ask another man to live for mine.

  11. #10
    Aziz's Avatar
    Aziz is offline no investment, no glory
    Join Date
    May 2009
    Location
    IL
    Posts
    736
    Thanks
    588
    Thanked 243 Times in 168 Posts
    the 404.php in a wordpress theme somehow overrides the .htaccess code

Page 1 of 2 12 LastLast

Similar Threads

  1. 300,000 posts and new main page!
    By Nextstep in forum Community Building
    Replies: 3
    Last Post: 12 June, 2010, 22:40 PM
  2. The Subway Topic Main List
    By StephenM in forum General Chat
    Replies: 4
    Last Post: 20 April, 2010, 17:21 PM
  3. Replies: 8
    Last Post: 6 April, 2010, 08:08 AM
  4. Your Main Networking Tool As A Freelancer
    By Farrhad A in forum Freelancing
    Replies: 7
    Last Post: 9 August, 2009, 09:38 AM
  5. Internet business as main job
    By akira07 in forum Business
    Replies: 27
    Last Post: 1 June, 2009, 12:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •