0

I have taken several stabs at this, but have not been able to hit on the correct syntax. Any help would be greatly appreciated. My .htaccess file reads as you see below. Up until now it has been doing what it should:Redirecting all visitors on smart phones, etc. to the mobile version of my web site. But now I need to add a command which exempts certain folders in my file manager from the effects of .htaccess. What needs to be added to my code?

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.mconchicago.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://m.mconchicago.com [R,L]
Eric Ellis
  • 33
  • 8
  • Just as an aside about what you are doing: please do make sure that the full version is available from smartphones as well. I hate it when something works poorly in the mobile version and my phone is able to handle the full site just fine, but I have to change what my browser reports as its user agent to even get to that full site. – Jasper Oct 23 '12 at 21:08
  • Thanks for your feedback. There has always been a link for the full site. However the way you are thinking about it is a new perspective for me. – Eric Ellis Oct 25 '12 at 02:20

1 Answers1

0

I've been trying to figure this out for months. Tonight the odyssey finally ended. I changed this section:

RewriteEngine on
RewriteBase /

To read like this:

RewriteEngine on
RewriteRule ^family($|/) - [L]
RewriteRule ^photos($|/) - [L]
RewriteRule ^info($|/) - [L]
RewriteBase /

Now it works like a charm. "family", "photos" and "info" are the folders that are being exempted from the effects of .htaccess. Hopefully this info will save time for someone else.

Eric Ellis
  • 33
  • 8