我想只有当用户通过移动设备访问该网站重定向特定页面其他特定网页。 到目前为止,我有下面的代码,但它不工作,我不确定为什么。 请指教。
#=== Start Mobile Redirection ===
# Check if this is the noredirect query string
RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
# Can not read and write cookie in same request, must duplicate condition
RewriteCond %{QUERY_STRING} !(^|&)noredirect=true(&|$)
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP_COOKIE} !^.*noredirect=true.*$ [NC]
# Now redirect to the mobile site
RewriteRule ^/index/albums/review(.*)$ /index/mobile/album$1 [R,L]
RewriteRule ^/index/albums/upcoming(.*)$ /index/mobile/albums-upcoming$1 [R,L]
RewriteRule ^/index/albums(.*)$ /index/mobile/albums$1 [R,L]
RewriteRule ^/index/artists/info(.*)$ /index/mobile/artist$1 [R,L]
RewriteRule ^/index/hip-hop/best(.*)$ /index/mobile/best$1 [R,L]
RewriteRule ^/index/music-charts/albums(.*)$ /index/mobile/chart-albums$1 [R,L]
RewriteRule ^/index/music-charts/entry(.*)$ /index/mobile/chart$1 [R,L]
RewriteRule ^/index/music-charts(.*)$ /index/mobile/charts$1 [R,L]
RewriteRule ^/index/hip-hop/downloads(.*)$ /index/mobile/downloads$1 [R,L]
RewriteRule ^/index/news/entry(.*)$ /index/mobile/feature$1 [R,L]
RewriteRule ^/index/news(.*)$ /index/mobile/features$1 [R,L]
RewriteRule ^/index/mixtapes/entry(.*)$ /index/mobile/mixtape$1 [R,L]
RewriteRule ^/index/mixtapes(.*)$ /index/mobile/mixtapes$1 [R,L]
RewriteRule ^/index/playlists/entry(.*)$ /index/mobile/playlist$1 [R,L]
RewriteRule ^/index/playlists(.*)$ /index/mobile/playlists$1 [R,L]
RewriteRule ^/index/tracks/review(.*)$ /index/mobile/track$1 [R,L]
RewriteRule ^/index/tracks(.*)$ /index/mobile/tracks$1 [R,L]
RewriteRule ^/(.*) /index/mobile/ [R,L]
#=== End mobile Redirection ===
编辑:最终的解决方案张贴在这里。 由于乔恩林
#=== Start Mobile Redirection ===
# Check if this is the noredirect query string
RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]
# Can not read and write cookie in same request, must duplicate condition
RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$) [OR]
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP_COOKIE} ^.*noredirect=true.*$ [NC]
RewriteRule ^ - [L]
RewriteCond %{HTTP:x-wap-profile} ^$
RewriteCond %{HTTP:Profile} ^$
RewriteCond %{HTTP_USER_AGENT} !"acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC]
RewriteCond %{HTTP_USER_AGENT} !"dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC]
RewriteCond %{HTTP_USER_AGENT} !"maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC]
RewriteCond %{HTTP_USER_AGENT} !"palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC]
RewriteCond %{HTTP_USER_AGENT} !"sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC]
RewriteCond %{HTTP_USER_AGENT} !"teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC]
RewriteCond %{HTTP_USER_AGENT} !"wapp|wapr|webc|winw|winw|xda|xda-" [NC]
RewriteCond %{HTTP_USER_AGENT} !"up.browser|up.link|windowssce|iemobile|mini|mmp" [NC]
RewriteCond %{HTTP_USER_AGENT} !"symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
RewriteRule ^ - [L]
# Now redirect to the mobile site
RewriteRule ^index/albums/review(.*)$ /index/mobile/album$1 [R,L]
RewriteRule ^index/albums/upcoming(.*)$ /index/mobile/albums-upcoming$1 [R,L]
RewriteRule ^index/albums(.*)$ /index/mobile/albums$1 [R,L]
RewriteRule ^index/artists/info(.*)$ /index/mobile/artist$1 [R,L]
RewriteRule ^index/hip-hop/best(.*)$ /index/mobile/best$1 [R,L]
RewriteRule ^index/music-charts/albums(.*)$ /index/mobile/chart-albums$1 [R,L]
RewriteRule ^index/music-charts/entry(.*)$ /index/mobile/chart$1 [R,L]
RewriteRule ^index/music-charts(.*)$ /index/mobile/charts$1 [R,L]
RewriteRule ^index/hip-hop/downloads(.*)$ /index/mobile/downloads$1 [R,L]
RewriteRule ^index/news/entry(.*)$ /index/mobile/feature$1 [R,L]
RewriteRule ^index/news(.*)$ /index/mobile/features$1 [R,L]
RewriteRule ^index/mixtapes/entry(.*)$ /index/mobile/mixtape$1 [R,L]
RewriteRule ^index/mixtapes(.*)$ /index/mobile/mixtapes$1 [R,L]
RewriteRule ^index/playlists/entry(.*)$ /index/mobile/playlist$1 [R,L]
RewriteRule ^index/playlists(.*)$ /index/mobile/playlists$1 [R,L]
RewriteRule ^index/tracks/review(.*)$ /index/mobile/track$1 [R,L]
RewriteRule ^index/tracks(.*)$ /index/mobile/tracks$1 [R,L]
RewriteRule ^(?!index/mobile/)(.*) /index/mobile/ [R,L]
#=== End mobile Redirection ===