htaccess mobile redirect for specific url

2019-09-18 01:45发布

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.

2条回答
Ridiculous、
2楼-- · 2019-09-18 02:04

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.

查看更多
The star\"
3楼-- · 2019-09-18 02:08

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]
查看更多
登录 后发表回答