Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
www.example.com或example.com使用.htaccess进行移动重定向_.htaccess_Redirect_Mobile - Fatal编程技术网

www.example.com或example.com使用.htaccess进行移动重定向

www.example.com或example.com使用.htaccess进行移动重定向,.htaccess,redirect,mobile,.htaccess,Redirect,Mobile,我将很快开始我的网站的移动版本,已经为其设置了如下空间: 我在这里找到了一个解决方案: ^这似乎工作得很好,但当我在iphone4上尝试时,只有在url中输入www时,它才会重定向。。如果我忽略它,我只会得到我的常规网站 因此,如果用户进入www.example.com或example.com,我需要移动重定向才能工作 我对代码做了一些修改,使它几乎正常工作。现在它适用于两个版本的url,但我必须刷新一次才能获得移动站点。显然,我希望重定向在他们第一次访问网站时起作用。我肯定我遗漏了什么,让

我将很快开始我的网站的移动版本,已经为其设置了如下空间:

我在这里找到了一个解决方案:

^这似乎工作得很好,但当我在iphone4上尝试时,只有在url中输入www时,它才会重定向。。如果我忽略它,我只会得到我的常规网站

因此,如果用户进入www.example.com或example.com,我需要移动重定向才能工作

我对代码做了一些修改,使它几乎正常工作。现在它适用于两个版本的url,但我必须刷新一次才能获得移动站点。显然,我希望重定向在他们第一次访问网站时起作用。我肯定我遗漏了什么,让我知道你的想法。顺便说一句,我的主机是aplus.net

RewriteCond %{HTTP_HOST} ^(www\.example\.com|example\.com) [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://mobile.example.com/$1 [L,R=302]
回复林琼恩

是的,my.htaccess中还有一些其他规则

定义不同的索引页类型:

DirectoryIndex index.html index.htm INDEX.HTML INDEX.HTM Index.html Index.htm default.htm Default.htm index.shtml index.cgi index.php index.php3 index.jsp index.phtml
从URL中删除.php扩展名

Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
然后这是从cp自动输入的:

# [ CP Global Redirection - Start ]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{SERVER_NAME} !^www\..*$
RewriteRule ^(.*)$ http://www.%{SERVER_NAME}/$1 [R]
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{SERVER_NAME} !^www\..*$
RewriteRule ^(.*)$ https://www.%{SERVER_NAME}/$1 [R]
</IfModule>
# [ CP Global Redirection - End ]
#[CP全局重定向-启动]
重新启动发动机
重写cond%{SERVER\u PORT}^443$
重写cond%{SERVER_NAME}^www\*$
重写规则^(.*)$http://www.%{SERVER_NAME}/$1[R]
重写cond%{SERVER_PORT}^443$
重写cond%{SERVER_NAME}^www\*$
重写规则^(.*)$https://www.%{SERVER_NAME}/$1[R]
#[CP全局重定向-结束]

下面是我们在Aplus.net平台上为移动应用程序使用的移动重定向代码。应该能够使用此重定向到您自己的自定义站点

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:X-WAP-PROFILE} !^$ [OR]
RewriteCond %{HTTP:PROFILE} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(Alcatel|Asus|Android|BlackBerry|Ericsson|Fly|Huawei|i-mate|iPAQ|iPhone|iPod|LG-|LGE-|MDS_|MOT-|Nokia|Palm|Panasonic|Pantech|Philips|Sagem|Samsung|Sharp|SIE-|Symbian|Vodafone|Voxtel|WebOS|Windows\s+CE|ZTE-|Zune).*$ [NC,OR]
RewriteCond %{HTTP_ACCEPT} application/vnd.wap.xhtml\+xml [NC,OR]
RewriteCond %{HTTP_ACCEPT} text/vnd.wap.wml [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{SERVER_NAME} ^www\.(.*)$
RewriteRule ^(.*) http://mobile.%1/ [L]
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:X-WAP-PROFILE} !^$ [OR]
RewriteCond %{HTTP:PROFILE} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(Alcatel|Asus|Android|BlackBerry|Ericsson|Fly|Huawei|i-mate|iPAQ|iPhone|iPod|LG-|LGE-|MDS_|MOT-|Nokia|Palm|Panasonic|Pantech|Philips|Sagem|Samsung|Sharp|SIE-|Symbian|Vodafone|Voxtel|WebOS|Windows\s+CE|ZTE-|Zune).*$ [NC,OR]
RewriteCond %{HTTP_ACCEPT} application/vnd.wap.xhtml\+xml [NC,OR]
RewriteCond %{HTTP_ACCEPT} text/vnd.wap.wml [NC]
RewriteRule ^(.*) http://mobile.%{HTTP_HOST}/ [L]

在您的服务器/vhost配置或htaccess中是否有其他重写规则或重定向设置?显然,我不熟悉如何回复此处的评论。我试图从我的.htaccess中粘贴其他规则,但看起来字符太多了?编辑你的帖子并将它们添加到底部非常感谢它已被编辑。我建议你使用基于Javascript的重定向,这比用户代理猜测的更健壮:嘿,大卫,非常感谢!这就像一个魅力,现在开始在移动网站上工作。