【问题标题】:Htacess Rule for redirect to a URL based on HOST Name基于主机名重定向到 URL 的 Htaccess 规则
【发布时间】:2014-04-23 05:43:53
【问题描述】:

我已经在服务器中配置了我的项目

示例http://www.example.com

那里面有一页http://www.example.com/products/index

现在我有其他新域http://dev.ny-sample.com需要点

我将新域指向 http://www.example.com/products/index

但是现在我需要在http://www.example.com/的HTACESS文件中写一条规则

【问题讨论】:

标签: php .htaccess


【解决方案1】:

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

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?nysample\.com$ [NC]
RewriteRule ^/?$ http://%{HTTP_HOST}/products/index [R=301,L]

【讨论】:

    【解决方案2】:

    试试看,对我来说效果很好。

    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule (.*) http://www.example.com/product/index [R=301,L]
    

    【讨论】:

      【解决方案3】:

      重写引擎开启

      重定向/http://dev-nysample.com/products/index

      【讨论】:

        【解决方案4】:

        最终我在 index.php 中采用了这种方式

        if($_SERVER['HTTP_HOST'] =='dev.ny-sample.com' && ($_SERVER['REQUEST_URI'] == "/")) { header('位置:http://dev.ny-sample.com/products/index/'); }

        我尝试了所有对我不起作用的 htaccess 方法,可能是我不知道正确的方法。

        【讨论】:

          猜你喜欢
          • 2016-09-20
          • 2015-07-14
          • 2017-08-29
          • 1970-01-01
          • 1970-01-01
          • 2018-11-20
          • 2021-05-20
          • 2019-01-17
          • 1970-01-01
          相关资源
          最近更新 更多