So what I am trying to do is send mobile users from the existing page to a mobile subdomain. Below is a working script that does this. However, I would like it to direct users to the correct mobile page. For example send www.domain.ca/pages/news.html to m.domain.ca/m_pages/m_news.html
The problem right now is that if a user enters for example from the RSS feed to the news page they are redirected to the main mobile page and not the news page.
I have a feeling that this is an easy question to answer, but am not familiar with the mod_rewrite operators.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^m\.domain\.ca$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteCond %{HTTP_COOKIE} !mobilecookie=true
RewriteRule ^(.*)$ http://m.domain.ca [L,R=302]
and on the mobile site a cookie is set to true upon arrival.
My current naming scheme is that all page names and folder names are t开发者_开发百科he same with m_ appended to the front. The folder structure is the same on both sites.
Summary of answers from comments:
RewriteRule ^(.*)$ http://m.domain.ca%{REQUEST_URI} [L,R=302]
- Keep file structure the same on both main domain and mobile site
Use the above code and follow the bullet tip to successfully redirect
精彩评论