anyone here know htaccess language?

Discussion in 'BlackHat Lounge' started by nonai, Feb 27, 2014.

  1. nonai

    nonai Power Member

    Joined:
    Oct 10, 2013
    Messages:
    524
    Likes Received:
    64
    Hi

    I want to accomplish the following:
    redirect non-www to www for all users
    redirect desktop users to www.example.com/homepage
    redirect mobile users to www.example.com/m

    Here is my htaccess code. The problem is, if I am on an iphone and I type www.example.com it DOES direct to /m BUT if I dont put www at the beginning, it says too many redirects and the page doesn't open. there might be more things wrong with the code, I just pieced them together from different websites and dont know what I'm doing, please help.

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    
    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ /homepage/ [R=301]
    </IfModule>
    
    RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
    RewriteRule ^(.*)$ http://www.example.com/m [R=301]
    RewriteCond %{HTTP_USER_AGENT} ^.*iPod.*$
    RewriteRule ^(.*)$ http://www.example.com/m [R=301]
    RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
    RewriteRule ^(.*)$ http://www.example.com/m [R=301]
    RewriteCond %{HTTP_USER_AGENT} ^.*iemobile.*$
    RewriteRule ^(.*)$ http://www.example.com/m [R=301]
    RewriteCond %{HTTP_USER_AGENT} ^.*blackberry.*$
    RewriteRule ^(.*)$ http://www.example.com/m [R=301]
    RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
    RewriteRule ^(.*)$ http://www.example.com/m [R=301]
    
     
  2. uncutu

    uncutu Elite Member

    Joined:
    Aug 6, 2010
    Messages:
    1,839
    Likes Received:
    1,005
  3. evilclown

    evilclown Senior Member

    Joined:
    Jul 31, 2012
    Messages:
    851
    Likes Received:
    595
    Occupation:
    Party Clown
    Location:
    Clownville
    I'm not gonna fix that code for you. But you have too many redirects. First you have the www and non-www and add to it the redirection based on the user-agent. First you need to handle the user-agent, then focus on the non-www.

    My recommendation use your platform to determine the user-agent and let your platform handle the display.
     
    Last edited: Feb 28, 2014