Go Back   SitePoint Forums > Forum Index > Host Your Site > Apache Configuration
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 20, 2009, 10:14   #1
ben319
SitePoint Member
 
Join Date: Nov 2009
Posts: 1
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]
ben319 is offline   Reply With Quote
Old Nov 20, 2009, 14:05   #2
dklynn
Hosting
silver trophybronze trophy
SitePoint Award Recipient
 
dklynn's Avatar
 
Join Date: Feb 2002
Location: Auckland
Posts: 11,065
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
dklynn is offline   Reply With Quote
Old Nov 22, 2009, 14:20   #3
ifuschini
SitePoint Member
 
Join Date: Nov 2009
Posts: 1
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 14:57. Reason: The URL is moduleS.apache.org and link added for members
ifuschini is offline   Reply With Quote
Reply

Bookmarks

Tags
mod_rewrite

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 13:02.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved