WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Redirect IE8 users to another site (14 posts)

  1. Mickey44
    Member
    Posted 2 years ago #

    I'm looking for a way of redirecting Internet Explorer 8 browser users to another site (IE8 is having problems displaying my new site so I want to send all IE8 users to another domain with my old site which displays fine). I've got the 'php-browser-detection' plugin installed but not sure how to set up a redirect. I know the code for a redirect is something like this:

    <meta http-equiv="Refresh" content="0; url=http://domaingoeshere/">

    And I think the code needs to go in here where 'do stuff' is.

    <?php if ( is_lt_IE8() ) { do stuff }; ?>

    I'm not a coder so I may have this totally wrong but if anyone can help that would be great. Thanks.

  2. kostas123
    Member
    Posted 2 years ago #

    "meta" redirection isn't recomended :
    1)because it could break the "back" button functionality
    2) search engines rank your page lower because Meta-redirect is evaluated as " black hat SEO techniques " .
    An alternative solution could be :

    // PHP tags are not included
    if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 8') )
    {
    header( 'Location: h ttp://www.tournasdimitrios.host56.com' ) ;
    }

    I made the test on my development environment and it works .
    Do the test and let me know ...

  3. Mickey44
    Member
    Posted 2 years ago #

    Thanks kostas

    Where do I need to enter this code, in the php-browser-detect plugin code or in the code of the main site?

  4. Big Bagel
    Member
    Posted 2 years ago #

    You have to make sure it's called before any headers are sent or it'll crash and burn.

    I would put it in your theme's functions.php file and hook it to something early, like:

    add_action( 'init', 'redirect_ie' );
    
    function redirect_ie {
        if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) ) {
            header( 'Location: h ttp://www.example-domain.com' ) ;
        }
    }

    *Note:
    Make sure to take that extra space between the "h" and "t" out. It's only there to keep this forum from turning that into an actual link.

  5. kostas123
    Member
    Posted 2 years ago #

    Sorry I was not clear with my example .
    Although the example of Big-Bagel could be implemented .
    I suggest a simpler approach , open the header.php file of your theme and paste the code on the absolute top of the file .Don't forget to include the PHP-tags .
    Let us know if you need help .

  6. Mickey44
    Member
    Posted 2 years ago #

    Thanks guys, I'll give it a go.

  7. Mickey44
    Member
    Posted 2 years ago #

    I tried entering this at the top of the header code but just got a blank page instead of the homepage:

    <?php
    add_action( 'init', 'redirect_ie' );
    
    function redirect_ie {
        if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) ) {
            header( 'Location: http://domaingoeshere/' ) ;
        }
    }
    ?>
  8. Big Bagel
    Member
    Posted 2 years ago #

    If you're adding it to the top of your header.php file you should just use:

    <?php if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) ) {
        header( 'Location: h ttp://domaingoeshere/'; ) ;
    } ?>

    and make sure it is literally the very first thing in the file.

    The code I suggested in my earlier post would be if you added it to your functions.php file.

  9. Mickey44
    Member
    Posted 2 years ago #

    It didn't work, I just get a blank screen instead of the homepage. Also tried adding the earlier code to the functions.php but this totally crashed the site (had to replace the functions.php with a backup to get it to work again).

  10. Big Bagel
    Member
    Posted 2 years ago #

    Did you copy the code in my last post, because it has an extra ";"

    The right code would be:

    <?php if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) ) {
        header( 'Location: h ttp://domaingoeshere.com' );
    } ?>

    If you're getting a blank screen it means php is having a problem. I'll test it to see if there's a syntax issue I'm not seeing.

  11. Mickey44
    Member
    Posted 2 years ago #

    I'll try that and get back to you, thanks man.

  12. Big Bagel
    Member
    Posted 2 years ago #

    Yup, tested it and it worked fine. Just make sure it's the first thing in the header.php file and that you replace (h ttp://domaingoeshere.com) with whatever site you want. Also, (this is probably obvious, but I just wanted make sure) be sure to use Internet Explorer 8 to test it. You can change 'MSIE 8' to 'MSIE 9' or 'MSIE 7' if you need to use a different version.

  13. kostas123
    Member
    Posted 2 years ago #

    @Mickey44
    Paste the code of your header.php file into Pastebin and post the link here .
    We will make the necessary corrections .

  14. Mickey44
    Member
    Posted 2 years ago #

    Yes, works great, thank you Big Bagel. My new site now works perfectly as before in Safari, Firefox and Chrome and I've tested it in IE8 (had to first clear the cache, history etc) and it now redirects to my old site :) Also thanks to kostas123 for your help.

    Just in case you're interested the problem I was having with IE8 was displaying PNG files correctly. They display correctly in every other major browser but have rendering problems in IE8. The PNG files display fine in IE9 as they appear to have now sorted the problem.

    Thanks again guys.

Topic Closed

This topic has been closed to new replies.

About this Topic