【问题标题】:What happens to old redirects when dns change is done完成 dns 更改后旧重定向会发生什么
【发布时间】:2014-02-05 14:05:41
【问题描述】:

我的站点 mobil.test.nu 有一个重定向规则。

# For mobile devices:
RewriteCond %{HTTP_USER_AGENT} (android|blackberry|iphone|ipod|windows\ phone) [NC]
RewriteRule ^ http://test.nu/ [L,R=301]

# For non-mobile devices:
RewriteRule ^/?$   http://test.nu/mobil/index.htm [L,R=301]
RewriteRule ^(.*)$ http://test.nu/mobil$1 [L,R=301]

一些请求正在重定向到 test.nu。

我正在将 mobil.test.nu 的 dns 更改为 test.nu。

我想我必须在 test.nu 中重新重写所有来自 mobil.test.nu 的请求。

有人可以告诉我如何在 dns 更改后识别来自 mobil.test.nu 的请求。

编辑 识别主机名并进行修改。

# For mobile devices:
RewriteCond %{HTTP_HOST} ^mobile\.test\.nu$ [NC]
RewriteCond %{HTTP_USER_AGENT} (android|blackberry|iphone|ipod|windows\ phone) [NC]
RewriteRule ^ http://test.nu/ [L,R=301]

# For non-mobile devices:
RewriteCond %{HTTP_HOST} ^mobile\.test\.nu$ [NC]
RewriteRule ^/?$   http://test.nu/mobil/index.htm [L,R=301]
RewriteRule ^(.*)$ http://test.nu/mobil$1 [L,R=301]

【问题讨论】:

    标签: .htaccess mod-rewrite redirect dns


    【解决方案1】:

    您需要添加检查 %{HTTP_HOST} 变量的条件:

    # For mobile devices:
    RewriteCond %{HTTP_HOST} !^mobile\.test\.nu$ [NC]
    RewriteCond %{HTTP_USER_AGENT} (android|blackberry|iphone|ipod|windows\ phone) [NC]
    RewriteRule ^ http://mobile.test.nu/ [L,R=301]
    
    # For non-mobile devices:
    RewriteCond %{HTTP_HOST} ^mobile\.test\.nu$ [NC]
    RewriteCond %{HTTP_USER_AGENT} !(android|blackberry|iphone|ipod|windows\ phone) [NC]
    RewriteRule ^/?$   http://test.nu/mobil/index.htm [L,R=301]
    
    RewriteCond %{HTTP_HOST} ^mobile\.test\.nu$ [NC]
    RewriteCond %{HTTP_USER_AGENT} !(android|blackberry|iphone|ipod|windows\ phone) [NC]
    RewriteRule ^(.*)$ http://test.nu/mobil$1 [L,R=301]
    

    不完全清楚您的规则应该做什么,因为我认为上述方法行不通。但本质上是:

    RewriteCond %{HTTP_HOST} ^mobile\.test\.nu$ [NC]
    

    会告诉你请求是否针对mobile.test.nu

    【讨论】:

    • 感谢您的回答。我想,我可以按照您的建议识别主机并编写规则。
    • 请帮我检查它们是否正确,规则不正确。我编辑了我的问题。
    • 即使在 dns 更改之后,我能否使用 RewriteCond %{HTTP_HOST} ^mobile\.test\.nu$ [NC] 捕获原始主机
    • @Patan “原始”主机是什么意思? %{HTTP_HOST} 变量是 URL 的 http://host/path/request 的“主机”部分
    • @Patan ! 表示“不匹配”,没有! 表示必须匹配
    猜你喜欢
    • 2015-02-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多