【问题标题】:How to redirect one domain to another如何将一个域重定向到另一个域
【发布时间】:2014-08-28 11:08:33
【问题描述】:

我有两个域:

www.example1.com/ --> IP=1.2.3.4
www.example2.com/ --> IP=1.2.3.4 (same IP for both domains)

我希望所有发往www.example2.com/* 的请求都能访问所请求的页面。 我希望所有发往www.example1.com/* 的请求都重定向到www.example2.com/*。我将如何在 apache 中执行此操作?现在我正在用 javascript 做这个。

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite httpd.conf


    【解决方案1】:

    将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com [NC]
    RewriteRule ^ http://www.example2.com%{REQUEST_URI} [NE,R=301,L]
    

    【讨论】:

    • 谢谢——这和我的apache2.conf文件在同一个目录吗?
    • DocumentRootapache2.conf 中定义,通常不相同。它类似于/var/www 或类似的东西。只需在您的 apache2.conf 文件中搜索 DocumentRoot
    猜你喜欢
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-27
    • 2015-03-21
    • 1970-01-01
    相关资源
    最近更新 更多