php - Modifying htaccess to redirect page to its mobile equivalent -


i have following htaccess rules in 1 of websites i'm working on:

 # ------------------- # custom php settings # -------------------  php_value include_path ".:/var/www/www.example.com/htdocs/custom/lib:/var/www/www.example.com/htdocs/common/lib:/usr/local/lib/php"  # long lib/ directory in include_path, these files found php_value auto_prepend_file common.header.php php_value auto_append_file  common.footer.php  php_value upload_max_filesize "50m" php_value post_max_size       "60m"  # ------------- # rewrite rules # -------------  rewriteengine   on rewritebase     / setenv          site_root /var/www/www.example.com/htdocs  # special case home dir (since it's outside of rewritebase) rewriterule ^/var/www/www.example.com/htdocs$ // [r,l]  # pretty urls detail pages rewriterule ^(.*)/~.+/(.*)/.*$ $1?id=$2 [l]  # webdav rewriterule ^webdav(/?.*)$ shared/webdav.php?p=$1 [l] rewriterule ^webdav_file(/?.*)$ shared/webdav_file.php?p=$1 [l]  #images-cache id rewritecond %{query_string} ^.*(id=.*)$ rewritecond %{la-f:env:site_root}/content/cache/images/%1 -f rewriterule ^.*/?images/display.php content/cache/images/%1 [l]  #images-cache folder+name rewritecond %{la-f:env:site_root}/content/cache/images/$2 -f rewriterule ^(.*)/?images/(.*) content/cache/images/$2 [l]  #style-cache rewritecond %{la-f:env:site_root}/content/cache/style/$2 -f rewriterule ^(.*)/?style/(.*) content/cache/style/$2 [l]   #fix pdf index pages rewriterule ^(.*)/.pdf$ $1/index.pdf [r,l,qsa] rewriterule ^.pdf$ index.pdf [r,l,qsa]  #pdf-cache folder+name rewritecond %{query_string} ^(.*)$ rewritecond %{la-f:env:site_root}/content/cache/pdf/$1%1 -f rewriterule ^(.*).pdf content/cache/pdf/$1%1 [l]  #pdf-cache folder+name rewritecond %{query_string} ^$ rewritecond %{la-f:env:site_root}/content/cache/pdf/$1 -f rewriterule ^(.*).pdf content/cache/pdf/$1 [l]   # if file directory without trailing slash, add slash , rewritecond %{la-f:env:site_root}/custom/$1 -d rewriterule ^(.+[^/])$ $1/ [r,l] rewritecond %{la-f:env:site_root}/common/$1 -d rewriterule ^(.+[^/])$ $1/ [r,l]  # first specified file in exact location specified.  (for internal rewrites) rewritecond %{la-f:env:site_root}/$1 -f rewriterule ^(.*)$ - [l]  # admin logo in config dir before anywhere else rewritecond %{la-f:env:site_root}/config/clientlogo_$1.$2 -f rewriterule ^themes/(.*)/images/hdr_clientlogo.(gif|jpg|jpeg)$ config/clientlogo_$1.$2 [l]  # specified file in custom , common rewritecond %{la-f:env:site_root}/custom/$1 -f rewriterule ^(.*)$ custom/$1 [l] rewritecond %{la-f:env:site_root}/common/$1 -f rewriterule ^(.*)$ common/$1 [l]  # in non-versioned content dir rewritecond %{la-f:env:site_root}/content/$1 -f rewriterule ^(.*)$ content/$1 [l]  # index pages (since last rule break auto-index files) rewritecond %{la-f:env:site_root}/custom/$1/index.php -f rewriterule ^(.*)/$ custom/$1/index.php [l] rewritecond %{la-f:env:site_root}/common/$1/index.php -f rewriterule ^(.*)/$ common/$1/index.php [l]  # index.html rewritecond %{la-f:env:site_root}/custom/$1/index.html -f rewriterule ^(.*)/$ custom/$1/index.html [l] rewritecond %{la-f:env:site_root}/common/$1/index.html -f rewriterule ^(.*)/$ common/$1/index.html [l]   # special case root index file rewritecond %{la-f:env:site_root}/custom/index.php -f rewriterule ^$ custom/index.php [l] rewritecond %{la-f:env:site_root}/common/index.php -f rewriterule ^$ common/index.php [l]  # try stripping off section (the first directory) rewritecond %{la-f:env:site_root}/custom/$1/$2 -f rewriterule ^([a-za-z0-9_]+)/.*/(.*)$ custom/$1/$2 [l] rewritecond %{la-f:env:site_root}/common/$1/$2 -f rewriterule ^([a-za-z0-9_]+)/.*/(.*)$ common/$1/$2 [l]  # if haven't found yet, in shared directory file. rewritecond %{la-f:env:site_root}/custom/shared/$1 -f rewriterule ([^/]+)$ custom/shared/$1 [l] rewritecond %{la-f:env:site_root}/common/shared/$1 -f rewriterule ([^/]+)$ common/shared/$1 [l]  # rewrite image directory >-------------------------------------------------  # if file still has not been found, in global images/ directory # (if path has images/ in rewritecond %{la-f:env:site_root}/custom/images/$2 -f rewriterule ^(.*)/?images/(.*) custom/images/$2 [l] rewritecond %{la-f:env:site_root}/common/images/$2 -f rewriterule ^(.*)/?images/(.*) common/images/$2 [l]  # rewrite rule image library rewriterule ^(.*)/?images/(.*) common/images/display.php?filename=$2 [l,qsa]  rewritecond %{request_uri} .pdf rewriterule ^(.*).pdf$ common/shared/make.pdf.php [l,qsa]   # stylesheets in custom/common rewritecond %{la-f:env:site_root}/custom/style/$2 -f rewriterule ^(.*)/style/(.*) custom/style/$2 [l] rewritecond %{la-f:env:site_root}/common/style/$2 -f rewriterule ^(.*)/style/(.*) common/style/$2 [l]  # dynamic stylesheets >----------------------------------------------------- rewritecond %{la-f:env:site_root}/custom/style/display.php -f rewriterule style/(.*) custom/style/display.php [l] rewriterule style/(.*) common/style/display.php [l]  # javascript in custom/common rewritecond %{la-f:env:site_root}/custom/js/$2 -f rewriterule ^(.*)/js/(.*) custom/js/$2 [l] rewritecond %{la-f:env:site_root}/common/js/$2 -f rewriterule ^(.*)/js/(.*) common/js/$2 [l]  # rewrite old urls , other domains >----------------------------------  # cms dynamic pages >------------------------------------------------------- #mobile rewritecond %{request_uri} !^/mobile/ rewritecond %{request_uri} !(.*)\.(.*){2,4} rewritecond %{http_user_agent} !^.*ipad.*$ [nc] 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 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-|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.+mobile" [nc] rewriterule (.*)$ http://www.example.com/mobile/ [r,l,qsa]  # send else shared/content.php further processing rewritecond %{la-f:env:site_root}/custom/shared/content.php -f rewriterule ^(.*)$ custom/shared/content.php [l] rewriterule ^(.*)$ common/shared/content.php [l] 

there page on website, let's say: http://example.com/articles/detail/news/my-article works fine on desktop; however, when viewed on mobile device, redirects mobile homepage. url redirected mobile version, similar http://example.com/mobile/news/news_detail?id=123.

is there way can define in above htaccess rules (just particular url) redirect mobile version if viewed on mobile?

thank you

you can this:

# set env variable mobile agents 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 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-|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.+mobile" [nc] rewritecond %{http_user_agent} !^.*ipad [nc] rewriterule ^ - [e=mobile_agent:1]  # handle 1 specific page rewritecond %{env:mobile_agent} =1 rewriterule ^articles/detail/news/my-article/?$ /mobile/news/news_detail?id=123 [l,nc,r=302]  # rest of uris rewritecond %{env:mobile_agent} =1 rewritecond %{the_request} !/mobile/ [nc] rewriterule !\.[a-za-z]{2,4}$ /mobile/ [nc,l,r=302] 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -