title: Rewrite url & redirect to mobile page in one htaccess
body: <p>I want to rewrite my sites' URL's so that you don't have to put the '.html' at the end, and I also want to redirect to a mobile page when you are a phone user, in my .htaccess file.</p>
  <p>Right now I can't get both codes (I copied) to work together; My desktop site seems to work fine with the rewriting, but on the mobile page, I get the 'too many redirects' error. I am very new to the rewriting and redirecting so perhaps the answer is quite simple...</p>
  <p>below is my .htaccess code:</p>
  <pre><code>  RewriteEngine On
    RewriteBase /
  
    RewriteCond %{HTTP_HOST} !^$
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://%{HTTP_HOST}%{REQUEST_URI} [R=301]
  
    RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
    RewriteRule (.*)\.html$ $1 [R=301]
  
    RewriteRule (.*)/index$ $1/ [R=301]
  
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} /$
    RewriteRule (.*)/ $1 [R=301]
  
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule (.*) $1\.html [L]
  &lt;/IfModule&gt;
  
  # Check if mobile=1 is set and set cookie 'mobile' equal to 1
      RewriteCond %{QUERY_STRING} (^|&amp;)mobile=1(&amp;|$)
      RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]
  
      # Check if mobile=0 is set and set cookie 'mobile' equal to 0
      RewriteCond %{QUERY_STRING} (^|&amp;)mobile=0(&amp;|$)
      RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]
  
      # cookie can't be set and read in the same request so check
      RewriteCond %{QUERY_STRING} (^|&amp;)mobile=0(&amp;|$)
      RewriteRule ^ - [S=1]
  
      # Check if this looks like a mobile device
      RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
      RewriteCond %{HTTP_USER_AGENT} &quot;android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile&quot; [NC,OR]
      RewriteCond %{HTTP:Profile}       !^$
  
      # Check if we're not already on the mobile site
      RewriteCond %{HTTP_HOST}          !^m\.
      # Check to make sure we haven't set the cookie before
      RewriteCond %{HTTP:Cookie}        !\mobile=0(;|$)
      # Now redirect to the mobile site
      RewriteRule ^ http://m.danielsante.com%{REQUEST_URI} [R,L] ```
  </code></pre>