mobile redirect script

by 2 replies
3
I have a short Java(?) script that redirects to a mobile optimized site based on the screen resolution, but found out that this does not work for all smartphones. I read that there are php scripts that do a better job, but I also read that you cannot place a php redirect script on a page that has an html extension. Is this true? If so, then what can I use for clients who have html websites? I am totally ignorant when it comes to programming languages.
#programming #mobile #redirect #script
  • Ok,

    If your customer has all HTML sites, then it's true, you can't really do a PHP redirect. But, this is not really a problem, because you can use any HTML in any PHP file. So, for example, when you type www.whateverdomain.com, the main file that will load by default, will be index.html

    So, if you copy this file, exactly as it is and name it index.php, it should load as well. You can try it by going to www.whateverdomain.com/index.php and the contents should be the same as your index.html

    Then, what you can do, at the top of the index.php file in the source code, you can use the following line:

    <?php
    header( 'Location: http://www.whateverdomain.com/new_page.html' ) ;
    ?>

    And that should work.

    Let me know if you have any other questions.

    - Max
  • I had to do this for a client before who had a regular version and a mobile version of their site, and wanted mobile users to automatically be redirected to the mobile version. They also wanted to give mobile users the option to view the full site if desired.

    I accomplished it using purely PHP and cookies for the view full version option, and it worked nicely. I highly recommend having a look at the Mobile ESP Project here: The MobileESP Project: Easily detect mobile web site visitors

    If you want to execute PHP inside a regular HTML file, you will need to modify the .htaccess file. Here's how to do it: Learning Journal - Parsing PHP in .html Files

    If you want to save yourself alot of time send me a PM and i will send you the code i wrote to do all of this. It was a little tricky figuring it all out...
    • [ 1 ] Thanks

Next Topics on Trending Feed

  • 3

    I have a short Java(?) script that redirects to a mobile optimized site based on the screen resolution, but found out that this does not work for all smartphones. I read that there are php scripts that do a better job, but I also read that you cannot place a php redirect script on a page that has an html extension. Is this true? If so, then what can I use for clients who have html websites? I am totally ignorant when it comes to programming languages.