Redirect 404 Errors to Home page

Home Forums BulletProof Security Pro Redirect 404 Errors to Home page

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #4518
    Joshua Wilson
    Participant

    Hello, how would i redirect 404 errors to the homepage. My service provider tried to do it but they said they couldn’t figure it out. I found this in the bottom of my .htaccess in my main roots. Im using the latest version of PRO

    RewriteRule ^404\.html$ "http\:\/\/sexualfantacys\.com\/" [R=301,L]
    #4520
    AITpro Admin
    Keymaster

    You would use the existing .htaccess code in your Root .htaccess file.  ErrorDocument is a redirect .htaccess directive.

    ErrorDocument 404 /404.php
    
    So what you would do is just add the path that you want to redirect too.  index.php would be your home page
    
    ErrorDocument 404 /index.php
    #4525
    AITpro Admin
    Keymaster

    Actually a much better thing to do would be to use your theme’s existing 404.php file located under your themes folder and add BPS Pro 404 error logging code in your theme’s 404.php file.

    Download the BPS Pro 404.php file from this folder – /wp-content/plugins/bulletproof-security/404.php

    Download your theme’s 404.php file from your themes folder – /wp-content/themes/your-theme-name/404.php

    Open both files and copy the BPS Pro 404.php error logging code into your theme’s 404.php file.

    In the BPS Pro 404.php file you will see this…

    BEGIN COPY CODE – BPS Error logging code

    // Copy this logging code from BEGIN COPY CODE above to END COPY CODE below and paste it right after in
    // your Theme’s 404.php template file located in your themes folder /wp-content/themes/your-theme-folder-name/404.php.

    After you have copied the BPS Pro 404.php error logging code into your theme’s 404.php file upload it back to your theme’s folder.

    If you changed the ErrorDocument directive path in your root .htaccess file then change it back to:  ErrorDocument 404 /404.php

     

    #4558
    Joshua Wilson
    Participant

    Hello i tried both ways and could not get it to work.  I get the same 404 themed page.  when i did a speed test it was a blank page.

    I just noticed the theme has another part to its 404.php  ,   content-404.php   is the data displayed when the error comes up.

    But that doesn’t explain why ErrorDocument 404 /index.php doesnt work.

    #4559
    AITpro Admin
    Keymaster

    If your Theme is fubar then that explains why everything is fubar.  Normally all WordPress themes will already redirect to your home page when a 404 error occurrs.  So switch your fubar theme to a good theme – WordPress 2012 and then test again.

    #4561
    Joshua Wilson
    Participant

    is there any mod_security rules?

    Does it matter where the ErrorDocument 404 /index.php is placed?

     

    #4563
    AITpro Admin
    Keymaster

    No it does not matter where it is in your .htaccess file – it is a stand alone directive.  Switch your junk theme to a good theme and test – WordPress 2012

    #4590
    Joshua Wilson
    Participant

    I’m still not getting the 404 page to redirect to the homepage.

    My main issue i am having, is i recently changed the permalinks on both my largest sites. I just scanned them both for a week and submitted my sitemaps.  Google gave me a bunch of errors on one of my sites and stopped crawling  for now and i cant fetch as Google and have constant server connectivity warning, due to just one day of have a bunch of errors. Its going to be a while before that site gets indexed, i have over 75,000 links.  I searched my links on google and i have a few thousand with the old permalinks. Its giving me the 404 errors.   Is there a way to rewrite the /shop   to  /product?

    Example.
    portalpetshop.com/shop/reptile-products/reptology-decorator-reptile-cage-black
    portalpetshop.com/product/reptile-products/reptology-decorator-reptile-cage-black

    #4598
    AITpro Admin
    Keymaster

    If the only thing that has changed in your URL structure is the category/folder structure/virtual URL structure is /shop to /product and the rest of the URL remains the same then this is the redirect that you need.  This will redirect all URL’s starting with /shop and redirect them to /product using a back reference.  I assume your custom permalink structure is:  /%category%/%postname%/.  This could potentially cause infinite redirect looping.  If it does then you are stuck with not being able to use the Regex (.*) match all and will have to use the rest or the actual URL /shop/reptile-products/reptology-decorator-reptile-cage-black

    RedirectMatch 301 ^/shop/(.*)$ http://www.ait-pro.com/product/$1

    Source:  http://forum.ait-pro.com/forums/topic/htaccess-redirect-code-where-do-i-add-redirect-htaccess-code/

    #4606
    AITpro Admin
    Keymaster

    Another less sophisticated approach that would not back reference the URL and would not create an infinite loop (if the code above does create an infinite redirect loop) and would only take care of all 404 errors with just 1 line of code would be this.  What this would do is redirect all requests to /shop to /product, but would not add the rest of the URL.  Like I said this would take care of all the 404 errors and be the next best thing to having to create 1,000’s of redirect lines of code for each URL.  It could be used as an interim fix until a more permanent solution is found.

    RedirectMatch 301 ^/shop/(.*)$ http://www.ait-pro.com/product/
    #4610
    Joshua Wilson
    Participant

    I tried both way but get a 500 interal server error. Could i be blocking one of the variables?  I backed up my other root .htaccess files.

    RedirectMatch 301 ^/shop/(.*)$ http: //www.portalpetshop.com/product/$1
    
    RedirectMatch 301 ^/shop/(.*)$ http: //www.portalpetshop.com/product/
    #4613
    AITpro Admin
    Keymaster

    A 500 error means you did not add the correct code.  You need to remove the space between http: and //.  I intentionally created a space so i do not have to deal with changing the anchor tag in the post.

    #4618
    AITpro Admin
    Keymaster

    After you have added this code then check 1 of your old URL’s.  If it redirects to the new URL without generating a redirect infinite loop error then you are good to go.

    #4619
    Joshua Wilson
    Participant

    It Worked!  Thank you greatly.   I thought the space was intentional because it was suppose to be there. But this is much better than just redirecting to the homepage.   🙂   Thank you greatly

    #4622
    AITpro Admin
    Keymaster

    Great!  Yeah I think the only time you would run into an infinite redirect loop problem would be in this type of scenario.

    You have an installation of WordPress installed in a folder off of the root folder.  Or in other words, a WordPress subfolder installation.  You also have a root folder installation of WordPress.  When you try to redirect a subfolder installation in this scenario it causes an infinite loop problem.

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.