SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Mobile Mod_Rewrite Issues - Too Many Redirects

    I'm redirecting the iPhone (and soon to be more mobile devices) successfully but in combination with some preexisting rewrite rules in my .htaccess file it's causing too many redirects.

    The mobile site is at mydomain.com/m and from mydomain.com it's trying to go to mydomain.com/m/?page=m&page=m&page=m&page=m etc.

    I'm new to mod_rewrite and any help you could offer would be great!

    Thanks!

    Code:
       ### REDIRECT MOBILE DEVICES
       RewriteCond %{HTTP_USER_AGENT} ^(.*iPhone.*)$
       RewriteCond %{REQUEST_URI} !^/m
       RewriteRule ^(.*)$ /m [L]
    
       ### OTHER REQUIRED REWRITE RULES BELOW
    
       ### CHECK FOR TRAILING SLASH - Will ignore files
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_URI} !/$
       RewriteCond %{REQUEST_URI} !(.*)/$
       RewriteRule ^(.*)$ /$1/ [L,R=301]
    
       ### MAIN REWRITE - This will ignore directories
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule ^(.*)\/$ /index.php?page=$1&%{QUERY_STRING}   [L]

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Ben,

    Well, the mod_rewrite for WAP-enabled phones used to be to echo a doctype in the file itself:
    Code:
    RewriteCond %{HTTP_ACCEPT} text/vnd\.wap\.wml
    With all the smartphones around today, that's pretty much been lost.

    Your code is fine for what it's trying to do UNTIL you get to the blocks after the iPhone. There, you must provide an exclusion for your m/ directory. Your last block will loop because you're only checking for the existence of a directory, not a file (which means that index.php is matched and you'll loop).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    there is a project called "Apache Mobile Filter" that allows you to access WURFL from any programming language, not just Java and php that is traditionally used for dynamic mobile web sites.

    The module detects the mobile device and passes the WURFL capabilities on to the other web application as environment variables. It can also be used to resize images on the fly to adapt to the screen size of the mobile device.

    Now this module is one of modules included in Apache Module Registry (modules.apache.org)

    For more info search "Apache Mobile Filter" on google
    Last edited by dklynn; Nov 22, 2009 at 15:57. Reason: The URL is moduleS.apache.org and link added for members


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
  •