htaccess mobile redirect for specific url

房东的猫 提交于 2019-12-13 04:03:07

问题


I have a created a duplicate m.website.com that have mobile friendly contents in them. However there are still some desktop page that I did not create a mobile version for it and I don't wish to redirect them to the mobile.

Is there a htaccess code which allows me to redirect just the pages that I wanted to the same url on the mobile site based on the user agent of their device and yet pages that does not have the mobile version created stays in the desktop version? I also want them to be able to choose if they want to go back to the desktop version if they want it to with the links that go back to the desktop page.

www.website.com/page1.htm to m.website.com/page1.htm and www.website.com/page2.htm stay in desktop version if there no mobile version of it.

Thanks for all the help.


回答1:


Try this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android"[NC]
RewriteRule ^page1\.htm$ http://m.website.com%{REQUEST_URI} [L,R=302,NC]



回答2:


You should be able to do it like this:

RedirectMatch 301 ^/contact\.php$ /contact-mobile.php

Just set up a redirect for each specific page you want redirected to a mobile version.



来源:https://stackoverflow.com/questions/20106417/htaccess-mobile-redirect-for-specific-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!