htaccess redirect Mobile

0

I wanted to do a redirect from the desktop site to the mobile site using htaccess. I already managed to do it, however I wanted to move the url from the desktop to the mobile url so I could handle the conversion.

Ex:

www.sitedesktop.com.br / # / categories / informatica / pagina / 3 /

I wanted to have htaccess redirect to mobile by passing the parameters after # /. The mobile index will have a variable to receive this parameter.

The real problem is, convert the url from the desktop to the mobile url, since the two are different. I just need to receive the url on the mobile that the client has accessed through the desktop to be able to handle it. If there is another way. :)

    
asked by anonymous 25.05.2017 / 14:49

1 answer

1

Following is an htaccess script for mobile redirection.

RewriteEngine on
RewriteBase /
# Checka se esta é uma string de consulta noredirect
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
# Seta o cookie, e pula para a próxima regra
RewriteRule ^ - [CO=mredir:0:www.website.com]

# Verifica se isso é um dispositivo móvel
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]

# Verifica se ainda não estamos em um site mobile.
RewriteCond %{HTTP_HOST}          !^m\.
# Não consigo ler e escrever cookies no mesmo pedido, deve duplicar a condição
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 

# Certifique-se de que não criamos o cookie antes
RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]

# Agora, redirecione para o site móvel
RewriteRule ^ http://m.website.com [R,L]

Source: Mobile Redirect using htaccess

    
25.05.2017 / 20:31