0

i have wordpress site and i have one page html m. site for mobile visitors. i want to redirect all the wordpress pages wen its mobile vistors to the m. (one page html). i use this code but its work only for the home page.

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:www.website.com]

# Check if this looks like a mobile device
# (You could add another [OR] to the second one and add in what you
#  had to check, but I believe most mobile devices should send at
#  least one of these headers)
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://m.website.com [R,L]

1 Answers1

0

To redirect all pages to the respective mobile page, you should be able to replace the last line by:

RewriteRule ^(.*)$ http://m.website.com/$1 [R,L]

EDIT: To redirect all pages to one single mobile page, use

RewriteRule ^(.*)$ http://m.website.com/ [R,L]

Apart from that, it is usually a better idea to not serve the same content at two places (problems: shared mobile links on desktop, search engines...) and instead use css media queries or server-side techniques to alter the style, if possible.

user1666456
  • 351
  • 1
  • 9
  • thanks fo the replay but its not work only the home page redirect to m. the other pages not redirect. have other idea? – Davie Locks Oct 26 '18 at 14:49
  • I just tested this exact configuration. Are you sure that you *replaced* the last line, that is, changed `^` to `^(.*)$` ? – user1666456 Oct 27 '18 at 10:38
  • Also: Where did you add the rules? Maybe they are interfering with the Wordpress rewrite rules? Maybe also see https://wordpress.stackexchange.com/questions/189767/redirect-to-other-page-when-mobile for a Wordpress-native solution (for you without `is_front_page()`) – user1666456 Oct 27 '18 at 10:49