in a previous post on stackoverflow there is this code, but it wasn't comprehensive. Something was missing. I copy this code into htaccess, and it is working fine now because I add also the mod_rewrite
module. Works splendid now.
Copy this code into your .htaccess and just change the name of domain. And you must wait couple of hours for DNS changes to propagate the Internet.
# Check if mobile=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]
# Check if mobile=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]
# cookie can't be set and read in the same request so check
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [S=1]
# Check if this looks like a mobile device
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [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 ^ https://m.neculaifantanaru.com%{REQUEST_URI}? [R,L]
############ https://neculaifantanaru.com ############
AddHandler application/x-httpd-ea-php56 .html .htm
AddType application/x-httpd-ea-php56 .html .htm
<IfModule mod_rewrite.c>
RewriteEngine On
<IfModule mod_autoindex.c>
IndexIgnore *
</ifModule>
</ifModule>
question from:
https://stackoverflow.com/questions/65944432/strip-query-string-issue-redirect-html-website-to-mobile-by-htaccess 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…