WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multisite Mobile Redirect (10 posts)

  1. tiaanswart
    Member
    Posted 1 year ago #

    Hello

    I want to redirect all users with a mobile browser to one of my network sites. Multisite is setup with subdirectories in this case "/mobile" is the mobile site.

    In my .htaccess file i placed the below code but for somereason it does not redirect? Please help!

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/mobile/.*$
    RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,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]
    RewriteRule ^(.*)$ /mobile/ [L,R=302]
  2. So you have multisite installed in domain.com

    And you have a subsite of 'mobile'

    Did you put that code above the WP calls?

  3. tiaanswart
    Member
    Posted 1 year ago #

    Yes i tried both, above and underneath the standard wp calls? Any ideas?

  4. First, always put it above :)

    Second, I think it should start with

    RewriteCond %{REQUEST_URI} !^mobile/.*$
  5. tiaanswart
    Member
    Posted 1 year ago #

    Hi

    Thanks a million! it worked however when on a mobile browser the redirect times-out with error: "Exceeded maximum redirect attempts to server"

  6. tiaanswart
    Member
    Posted 1 year ago #

    Also now when going to the mobile site directly i get the same error: "Exceeded maximum redirect attempts to server"

  7. tiaanswart
    Member
    Posted 1 year ago #

    hahaha yes i've tried everything before coming here...

    nothing seems to work right :(

  8. It's trickier with Multisite because it redirects things by default :/ So you're redirecting and redirecting (and this is part of why mobile responsive themes are all the rage).

  9. tiaanswart
    Member
    Posted 1 year ago #

    Hi Ipstenu

    I finally got this working after a long battle with WP MU Subdomain setup (and my host not being very helpful) I was able to setup a mobi site. (mobi.domain.co.za).

    I then added the below code to my htaccess header...

    RewriteEngine on
    RewriteBase /
    RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
    RewriteRule ^ - [CO=mredir:0:www.domain.co.za]
    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]
    RewriteCond %{HTTP_HOST}          !^mobi\.
    RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$)
    RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]
    RewriteRule ^ http://mobi.domain.co.za [R,L]

    And Viola...

    It worked :)

    Thanks a mil!
    T

Topic Closed

This topic has been closed to new replies.

About this Topic