【问题标题】:Nginx rewrite rule with variableNginx 用变量重写规则
【发布时间】:2014-01-02 23:46:30
【问题描述】:

我想将来自子域的所有请求发送到 index.php 并将子域名作为 $sub 发送

例如:

sub1.mydomain.com
send the above request to:
/var/www/mydomain/index.php?sub=sub1

我尝试过的:

rewrite ^(\w+).mydomain.com /index.php?sub=$1 last;
root /var/www/mydomain/;

【问题讨论】:

    标签: apache nginx rewrite


    【解决方案1】:

    重写在请求 URI 中完成。这不包含主机名。为变量 sub 分配默认值,然后使用 id 语句捕获替换默认值的子域。然后使用无条件重写。

    $sub=www;
    if($host ~ ^(\w+\.example.com$) {
        $sub = $1;
    }
    rewrite ^.*$ /index.php?sub=$sub$args;
    

    从我的头顶。使用相关文档对其进行调整。

    【讨论】:

      猜你喜欢
      • 2010-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 1970-01-01
      • 2015-03-04
      • 2013-08-05
      相关资源
      最近更新 更多