0

I am using an apache server and want to redirect mobile & tablet users.

Unfortunately there is something wrong with my .Htaccess file.

When I visit my website on mobile I get redirected, but it says there are to much redirections.

Here's my .htaccess file:

RewriteEngine on
RewriteBase /
# Check if this is the noredirect query string
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:http://Someurl.com]
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST}          !^m\.
# Can not read and write cookie in same request, must duplicate condition
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]
# Now redirect to the mobile site
RewriteRule ^ http://Someurl.com [R,L]
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ipad [NC]
RewriteCond %{REQUEST_URI} !^/tablet/. [NC]
RewriteRule ^ http://Someurl.com [L,R=301]
RewriteCond %{HTTP_USER_AGENT} android [NC]
RewriteCond %{HTTP_USER_AGENT} !mobile [NC]
RewriteCond %{REQUEST_URI} !^/tablet/. [NC]
RewriteRule ^ http://Someurl.com [L,R=301]

Thanks in advance

David Passmore
  • 6,089
  • 4
  • 46
  • 70
Merijn
  • 41
  • 1
  • 8
  • Please do not link to external resources, any extra resources should be placed directly in your question. – Ed Holloway-George May 21 '15 at 15:48
  • Thanks for your reaction, i tried this but unfortunately it removed some of the code. EDIT: Thanks for changing Ed – Merijn May 21 '15 at 15:49
  • Related: http://stackoverflow.com/questions/20818929/mobile-redirect-using-htaccess/20820566#20820566 – Sumurai8 May 21 '15 at 16:33
  • Besides that, that mess is unreadable. Take some time to add extra newlines so corresponding blocks of conditions and a rule are grouped together. Then give us the url you tried this with. – Sumurai8 May 21 '15 at 16:34
  • Sumurai8, Thank you very much. I'm new on Stackoverflow so i'm sorry for the mess – Merijn May 21 '15 at 16:53
  • @Merijn Welcome to Stackoverflow ;-) You can edit your question with the edit-link directly under your post. Improving your post will bump it back up for others to see. Besides that, higher quality questions are more likely to receive an useful answer. See [this help center article](http://stackoverflow.com/help/how-to-ask) – Sumurai8 May 22 '15 at 09:02

0 Answers0