【问题标题】:htaccess - subdomain as GET parameterhtaccess - 子域作为 GET 参数
【发布时间】:2012-03-22 00:53:03
【问题描述】:

我的.htaccess 文件中已有以下内容:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]

但我想添加这样的规则:

RewriteCond %{HTTP_HOST} ^(.+).example.com
RewriteRule ^(.*)% http://example.com/?name=%1&type=$1 [R,L]

但如果没有它绑定到example.com,它必须在任何域上工作。

【问题讨论】:

    标签: apache .htaccess mod-rewrite subdomain


    【解决方案1】:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^(www)\. [NC]
    RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.com [NC]
    RewriteRule (.*) http://www.%2.com/?name=%1 [R=301,L]
    

    http://subdomain.domain.com 重写为http://www.domain.com/?name=subdomain

    将两者结合起来尝试这样的事情

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{HTTP_HOST} !^(www)\. [NC]
    RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.com [NC]
    RewriteRule (.*) http://www.%2.com/index.php?route=$1&name=%1 [R=301,L]
    

    这会将http://subdomain.domain.com/hello-world 重定向到http://www.domain.com/index.php?route=hello-world&name=subdomain

    【讨论】:

    猜你喜欢
    • 2014-02-07
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-17
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    相关资源
    最近更新 更多