1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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:
    63
    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 Power Member

    Joined:
    Aug 6, 2010
    Messages:
    504
    Likes Received:
    182
  3. evilclown

    evilclown Senior Member

    Joined:
    Jul 31, 2012
    Messages:
    805
    Likes Received:
    575
    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