ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

PHP Redirect

August 02, 2009 11:53am

Subscribe [4]
  • #1 / Aug 02, 2009 11:53am

    The Design Core

    359 posts

    I am trying to set up a PHP redirect on my EE index page for iPhone users.

    I am using the following script at the top of my index template:

    <?php
    define('IPHONE_URL', 'http://www.thisismyiphoneurl.com');
    if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE || strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== FALSE)
    {
        header("Location: " . IPHONE_URL);
    }
    ?>

    When I visit my URL on an iPhone, I do not get redirected.

    Will this not work in an EE template?

  • #2 / Aug 02, 2009 8:07pm

    The Design Core

    359 posts

    OK. I figured out that I did not have “Allow PHP” set to yes for the index page.

    Once I set that correctly, the page redirected but it took me to a 200 OK page.

    It reads “The document has moved here” where “here” is a link to the page that it was supposed to redirect to.

    Any ideas why this is happening?

    Thanks.

  • #3 / Aug 02, 2009 8:55pm

    KomodoDave

    39 posts

    What’s the URL of the page it currently redirects to?

    Have you tried appending ‘/index.php’ or whatever your default page is/should be onto the end of the URL?

  • #4 / Aug 02, 2009 9:11pm

    The Design Core

    359 posts

    It does not show me the url of the 200 OK page.

    My iphone page is in a template group called iphone and the page I want to redirect to is the index page in that group.

    I have tried:
    http://www.myurl.com/index.php/iphone/
    http://www.myurl.com/index.php/iphone/index.php

    Both URLs work if I view either URL in a computer’s browser, but I get the 200 OK page for both URLs when I go to http://www.myurl.com/ on an iphone.

  • #5 / Aug 02, 2009 9:18pm

    KomodoDave

    39 posts

    It does not show me the url of the 200 OK page.

    My iphone page is in a template group called iphone and the page I want to redirect to is the index page in that group.

    I have tried:
    http://www.myurl.com/index.php/iphone/
    http://www.myurl.com/index.php/iphone/index.php

    Both URLs work if I view either URL in a computer’s browser, but I get the 200 OK page for both URLs when I go to http://www.myurl.com/ on an iphone.

    I’m no iPhone developer, so I don’t know the quirks of the browser or anything similar. I’d normally guess it’s maybe because you have a rule in your Apache’s .htaccess file that’s altering the redirection behaviour, but it can’t be if it works ok on a PC.

    Does the page display as desired if you go to the explicit URL via iPhone, i.e. if you visit either .../iphone or .../iphone/index.php on your iPhone does it display more than a blank page?

    I don’t think I’m going to be able to resolve this one for you if it does show something, doh.

  • #6 / Aug 02, 2009 9:23pm

    The Design Core

    359 posts

    It does display the correct page if I go directly to it on the iphone.

    I have tried testing the redirect code using a page that is outside of EE and it works fine so something in EE is the culprit.

    Thanks for trying! 😊

  • #7 / Aug 03, 2009 10:54am

    The Design Core

    359 posts

    Anyone else have any ideas as to what is going on here?

  • #8 / Aug 03, 2009 12:09pm

    KomodoDave

    39 posts

    <snip> see below.

  • #9 / Aug 03, 2009 12:11pm

    KomodoDave

    39 posts

    Anyone else have any ideas as to what is going on here?

    Hi again mp 😊

    Have you tried using Javascript to redirect client-side instead, to see whether it fares any better?

    if(navigator.userAgent.indexOf("iPhone") != -1 || navigator.userAgent.indexOf("iPod") != -1)
       window .location = "http://www.your-redirect-site.com/path/to/your/redirect";

    Remove the space after ‘window’ in the code, the forum’s security won’t let me write ‘window . location’ without spaces.

    Give that a whirl and let me know.

  • #10 / Aug 03, 2009 2:15pm

    The Design Core

    359 posts

    That works! Thanks a ton!

    I would still love to know the problem with the PHP method if anyone has an idea.

  • #11 / Aug 03, 2009 2:18pm

    Lisa Wess

    20502 posts

    Try exiting at the end of your PHP code.

  • #12 / Aug 03, 2009 2:26pm

    The Design Core

    359 posts

    That was the ticket!

    Thank you!

  • #13 / Nov 24, 2009 11:38pm

    minimal design

    356 posts

    Try exiting at the end of your PHP code.

    Just wanted to say thanks! I was pulling my hair for 5mn there… 😉

  • #14 / Dec 19, 2012 11:10am

    shuffm

    2 posts

    I just spent forever trying to solve the same issue.

    exit();

    This works.

    Thanks for the post.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases