【问题标题】:How can I redirect from one subdomain to another in .htaccess?如何在 .htaccess 中从一个子域重定向到另一个子域?
【发布时间】:2013-10-19 20:12:54
【问题描述】:

最近我们更改了一个子域的名称,现在我们需要将所有旧页面重定向到新的子域页面。

示例页面链接:

我的发现:当我尝试访问顶级子域时,它运行良好。

如何将旧子域上的所有 URL 重定向到新子域?

目前我在.htaccess文件中有以下代码,请指导解决问题

RewriteEngine on
RewriteCond %{HTTP_HOST} ^jquery\.webcodehelpers\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.jquery\.webcodehelpers\.com$
RewriteRule ^/?$ "http\:\/\/uieiq\.webcodehelpers\.com\/search\/label\/jquery\ interview\ questions" [R=301,L]

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite redirect


    【解决方案1】:

    这对我有用,并维护 URI:

    RewriteCond %{HTTP_HOST} ^jquery\.webcodehelpers\.com
    RewriteRule (.*)$ http://uieiq.webcodehelpers.com/$1 [R=301,L]
    

    我用它来将一个子域重定向到另一个子域。

    【讨论】:

    • 我无法让 %{REQUEST_URI} 按照另一篇文章中的建议工作。
    【解决方案2】:

    通过httpd.conf 启用mod_rewrite.htaccess,然后将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^jquery\.webcodehelpers\.com$ [NC]
    RewriteRule ^ http://uieiq.webcodehelpers.com%{REQUEST_URI} [L,R=301,NE]
    

    请阅读:Apache mod_rewrite Introduction

    【讨论】:

    • 嗨,anubhava,我添加了,但它仍然无法正常工作,代码在 .htaccess 文件中# -FrontPage- IndexIgnore .htaccess /.?? ~ *# * /HEADER /README /_vti RewriteEngine On RewriteCond %{HTTP_HOST} ^jquery\.webcodehelpers\.com$ [NC] RewriteRule ^ uieiq.webcodehelpers.com%{REQUEST_URI } [L,R=301,NE] 命令拒绝,允许从所有允许拒绝 命令拒绝,允许从所有拒绝 AuthName webcodehelpers.com AuthUserFile /home/webcodeh/public_html/_vti_pvt/service.pwd AuthGroupFile /home/webcodeh/public_html/_vti_pvt/service.grp
    • 请不要在评论中发布代码,它根本不可读。编辑您的问题并在那里发布您的代码。
    • 还要确保 jquery.webcodehelpers.com 主机的 DOCUMENT_ROOT/.htaccess 文件中有上述代码
    • hey anubhava,我在问题中添加了我的 htaccess 文件代码,请帮助我如何修改它
    猜你喜欢
    • 2016-03-26
    • 2014-03-16
    • 2019-01-12
    • 2013-08-04
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多