.htaccess重定向,排除子域

.htaccess重定向,排除子域,.htaccess,mod-rewrite,mobile,redirect,.htaccess,Mod Rewrite,Mobile,Redirect,我一直在研究我的问题,用很多方法重新编写它,但我似乎仍然找不到答案。也可能是做不到,希望有人能帮助我。我不太熟悉.htaccess文件,但我一直在为公司的公司网站创建一个移动网站 我想让它做的是,当你去移动网站,它会给你一个选择,看到我们的完整公司网站或移动网站。我有它重定向到该页面刚刚好,但当你选择看到完整的网站,它会重定向你回到同一页,而不是看到完整的网站。我的移动站点位于子目录“www.companysite.com/mobile”中。我可以拥有它吗?这样当你选择查看完整站点的选项时,它就

我一直在研究我的问题,用很多方法重新编写它,但我似乎仍然找不到答案。也可能是做不到,希望有人能帮助我。我不太熟悉.htaccess文件,但我一直在为公司的公司网站创建一个移动网站

我想让它做的是,当你去移动网站,它会给你一个选择,看到我们的完整公司网站或移动网站。我有它重定向到该页面刚刚好,但当你选择看到完整的网站,它会重定向你回到同一页,而不是看到完整的网站。我的移动站点位于子目录“www.companysite.com/mobile”中。我可以拥有它吗?这样当你选择查看完整站点的选项时,它就不会一直将你重定向到移动站点了?这是我现在的代码:

    RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} android
    RewriteRule .* http://companysite.com/mobile [R=301,L]

    RewriteCond %{HTTP_USER_AGENT} BlackBerry
    RewriteRule .* http://companysite.com/mobile [R=301,L]

提前谢谢你

我想你也可以查一下推荐人。如果推荐人是你自己的网站,你不做重定向。差不多

RewriteCond %{HTTP_USER_AGENT} android
RewriteCond %{HTTP_REFERER} !yoursite\.com
RewriteRule .* http://companysite.com/mobile [R=301,L]
编辑: 我应该给出完整的解决方案:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (android|BlackBerry)
RewriteCond %{HTTP_REFERER} !yoursite\.com
RewriteRule .* http://companysite.com/mobile [R=301,L]

我想你也可以查一下推荐人。如果推荐人是你自己的网站,你不做重定向。差不多

RewriteCond %{HTTP_USER_AGENT} android
RewriteCond %{HTTP_REFERER} !yoursite\.com
RewriteRule .* http://companysite.com/mobile [R=301,L]
编辑: 我应该给出完整的解决方案:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (android|BlackBerry)
RewriteCond %{HTTP_REFERER} !yoursite\.com
RewriteRule .* http://companysite.com/mobile [R=301,L]

有些人喜欢用饼干,但这有点棘手。样品溶液应为:

    ## Setting a cookie and variable for mobile users
    RewriteRule .* - [E=IsMobile:false]
    RewriteRule .*  - [E=MobileCookie:false]

    # Mobile Redirection
    # Blackberry
    #RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} "blackberry" [NC]
    RewriteRule ^$ http://mobile.website/ [L,R=302]
    # End Blackberry

    # Mobile Redirection for IPhone
    RewriteCond %{HTTP_USER_AGENT} "googlebot-mobile|iemobile|iphone|ipod|opera mobile" [NC]
    RewriteRule ^$ http://mobile.website/ [L,R=302]
    # End other IPhone

    # Mobile Redirection for other Mobile
    RewriteCond %{HTTP_USER_AGENT} "android|palmos|webos" [NC]
    RewriteRule ^$ http://mobile.website/ [L,R=302]

    # Set isMobile variable to true
    RewriteRule .* - [E=IsMobile:true]
    # End other Mobile

    ## Assume the mobile cookie is not set:
    RewriteRule .* - [E=MobileCookie:false]

    ## Checking for mobile cookie
    RewriteCond %{HTTP_COOKIE} gpf_mobileoff=true
    RewriteRule .* - [E=MobileCookie:true]

    ## Combining IsMobile & MobileCookie to make one rule
    RewriteRule .* - [E=ShowMobile:false]
    RewriteCond %{ENV:IsMobile} ^true$
    RewriteCond %{ENV:MobileCookie} !^true$
    RewriteRule .* - [E=ShowMobile:true]
    ########## End - Custom redirects
当然,您需要在上面的代码中更改mobile.website,并使用js或其他方法注入mobilecookie


就我个人而言,我更喜欢HTTP_引用条件。

有些人喜欢使用cookies,但这有点棘手。样品溶液应为:

    ## Setting a cookie and variable for mobile users
    RewriteRule .* - [E=IsMobile:false]
    RewriteRule .*  - [E=MobileCookie:false]

    # Mobile Redirection
    # Blackberry
    #RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} "blackberry" [NC]
    RewriteRule ^$ http://mobile.website/ [L,R=302]
    # End Blackberry

    # Mobile Redirection for IPhone
    RewriteCond %{HTTP_USER_AGENT} "googlebot-mobile|iemobile|iphone|ipod|opera mobile" [NC]
    RewriteRule ^$ http://mobile.website/ [L,R=302]
    # End other IPhone

    # Mobile Redirection for other Mobile
    RewriteCond %{HTTP_USER_AGENT} "android|palmos|webos" [NC]
    RewriteRule ^$ http://mobile.website/ [L,R=302]

    # Set isMobile variable to true
    RewriteRule .* - [E=IsMobile:true]
    # End other Mobile

    ## Assume the mobile cookie is not set:
    RewriteRule .* - [E=MobileCookie:false]

    ## Checking for mobile cookie
    RewriteCond %{HTTP_COOKIE} gpf_mobileoff=true
    RewriteRule .* - [E=MobileCookie:true]

    ## Combining IsMobile & MobileCookie to make one rule
    RewriteRule .* - [E=ShowMobile:false]
    RewriteCond %{ENV:IsMobile} ^true$
    RewriteCond %{ENV:MobileCookie} !^true$
    RewriteRule .* - [E=ShowMobile:true]
    ########## End - Custom redirects
当然,您需要在上面的代码中更改mobile.website,并使用js或其他方法注入mobilecookie


就我个人而言,我更喜欢HTTP\U引用条件。

获取用户内容的唯一方法是env var HTTP\U COOKIE(),但在大多数iPhone上,COOKIE被禁用。我会将检查添加到我的脚本中,并在会话中设置一个标志,以检查用户是否希望使用您网站的移动版本谢谢!我将对此进行研究:)如果您使用PHP并希望在脚本中实现这一点,您可以使用$_会话保存重定向的标志和标题(“位置:[url]”)。获取用户内容的唯一方法是env var HTTP_COOKIE(),但在大多数iPhone上,COOKIE是禁用的。我会将检查添加到我的脚本中,并在会话中设置一个标志,以检查用户是否希望使用您网站的移动版本谢谢!我将对此进行研究:)如果您使用PHP并希望在脚本中实现这一点,可以使用$\u会话保存重定向的标志和标题(“位置:[url]”)