我有一个由另一个网站作为子域名托管的网站。我想让它变得移动友好。到目前为止,我已经正确地将其重定向到该站点的移动版本(目前只兼容Galaxy S3电话解决方案),即index_m.php而不是index.php。我有可选的php页面文件的移动版本的审美部分的网站(菜单栏,标志,页脚等)。但是,当我更新时,我只想修改一组文件(实际站点内容),而不是两个。这在很大程度上是可行的,因为我有一个备用菜单栏php,它将用户发送到适当的移动页面。问题是,页面部分,如更新和高亮显示,链接到网站的各个部分使用的链接到桌面格式的页面。
这是我当前的htaccess内容。如何为特定文件添加另一组条件?(特别是games.php/games_m.php和history y.php/history_m.php)在同一个文件夹中?
Options +FollowSymLinks
RewriteEngine on
# if the browser accepts these mime-types, it's definitely mobile, or pretending to be
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
# a bunch of user agent tests
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"[NC]
RewriteCond %{HTTP_USER_AGENT} "android|googlebot-mobile|iemobile|ipod|#opera mobile|palmos|webos" [NC]
RewriteRule ^$ http://sc55.duke4.net/index_m.php [R=302]我知道通常情况下,移动页面会使用完全交替的子域或子文件夹,但正如我所说的,我只希望一次更新一组文件。我无法访问任何数据库系统或任何东西,这两个网站都可以从中提取数据。
发布于 2014-07-05 22:32:50
问题是,正如您可能意识到的,一组条件只适用于一条规则。如何添加遵循相同条件的规则?一个解决办法是重复这些条件,但那太重了。
更有效的解决方案是使用if-然后-else逻辑:否定条件,然后保持文件不动,跳过下列规则,因此在满足条件时适用这些规则。这个应该是这样的:
# Do we meet NONE of the conditions?
RewriteCond %{HTTP_ACCEPT} !(text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml) [NC]
RewriteCond %{HTTP_USER_AGENT} !(sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera) [NC]
RewriteCond %{HTTP_USER_AGENT} !(mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox) [NC]
RewriteCond %{HTTP_USER_AGENT} !(blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie) [NC]
RewriteCond %{HTTP_USER_AGENT} !(portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc) [NC]
RewriteCond %{HTTP_USER_AGENT} !(smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone) [NC]
RewriteCond %{HTTP_USER_AGENT} !(android|googlebot-mobile|iemobile|ipod|#opera mobile|palmos|webos) [NC]
# If so, THEN leave the request untouched (and optionally skip the following rules)
RewriteRule ^ - [L]
# If there are more non-mobile rewrite rules, skip the next two rules by using this instead:
# RewriteRule ^ - [L,S=2]
# ELSE (we meet some of the conditions):
RewriteRule ^/?$ http://sc55.duke4.net/index_m.php [L,R=302]
RewriteRule ^(games|history)\.php http://sc55.duke4.net/$1_m\.php [L,R]https://stackoverflow.com/questions/24590558
复制相似问题