0

We have setup and working a redirect to our mobile site/page, which is on the same domain. The issue we are running into is that all images and links that point outside of the /mobile directory appear broken and redirect people right back to only the mobile directory.

How can we serve images/content from directories outside of /mobile and still have html/php content requests go back through our mobile site?

RewriteEngine On
RewriteBase /
#RewriteCond %{HTTP_USER_AGENT}     (mobile|blackberry|webos|android|j2me|palm|nokia|samsung|symbian|windows.ce) [NC]
#RewriteCond %{REQUEST_URI} !^
#RewriteRule ^(.*)$ ^mobile [R=302,L]
Jason
  • 13
  • 2

1 Answers1

0

Try this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

# redirect everything other than css, js, images to /mobile/
RewriteCond %{HTTP_USER_AGENT} (mobile|blackberry|webos|android|j2me|palm|nokia|samsung|symbian|windows.ce) [NC]
RewriteCond %{REQUEST_URI} !^/mobile/ [NC]
RewriteCond %{REQUEST_URI} \.(?:jpe?g|gif|bmp|png|tiff|css|js)$ [NC]
RewriteRule ^(.*)$ /mobile/$1 [R=302,L]

# redirect /mobile/stories to /stories
RewriteRule ^mobile/(stories/*)$ /$1 [NC,R=302,L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I know this wasn't in the original request, but if we, by chance, wanted to allow users to access html/php pages on the regular site, via a mobile device how could we do that? Like if we wanted to redirect them, but only if they went to main pages like / /stories, etc. Pages we've made mobile versions of. – Jason Nov 05 '13 at 09:31
  • As per above rule it will redirect php/html requests from mobile will be redirected to `/mobile/` do you want skip this rule for specific requests. – anubhava Nov 05 '13 at 09:34
  • That would be great, if we could redirect for everything except: images, and particular pages. – Jason Nov 05 '13 at 09:35
  • When I use the code you provided I'm not getting any redirect. I wonder if there was a problem with my original code? – Jason Nov 05 '13 at 09:56
  • You need to replace your original code with my code. If that doesn't work post your complete htaccess in your question. – anubhava Nov 05 '13 at 10:04