【问题标题】:Include hostname into mod_rewrite RewriteRule在 mod_rewrite RewriteRule 中包含主机名
【发布时间】:2013-02-12 16:55:32
【问题描述】:

我在一个虚拟主机中有多个域,例如别名:example.com 是主要的,example1.com 和 example2.com 是别名

我需要将多个域重写为单个入口点,通过 GET 查询参数传递它,去掉 www 前缀,例如:

HOST -> rewrite to
www.example1.com/some/path -> [example.com]/index.php?q=domain/example1.com/some/path
    example2.com/some/path -> [example.com]/index.php?q=domain/example2.com/some/path

我当前的 .htaccess 无法正常工作

RewriteRule   ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule   ^(.*)/(.*) index.php?q=domain/$1/$2 [L,QSA]

更新1

尝试使用 RewriteMap - rewrite.map 它遵循

example-site.com www.examplesite.com
www.example-site.com www.examplesite.com

.htaccess

RewriteMap host2site txt:/var/www/rewrite.map
RewriteRule ^(.*)$ index.php?q=/domain/{host2site:$1|NOTFOUND} [PT]

但它会因 500 服务器错误而崩溃:(

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    试试

    RewriteCond %{HTTP_HOST} !=example.com [NC]
    RewriteRule ^(.*)$ http://example.com/index.php?q=domain/%{HTTP_HOST}/$1 [L,QSA]
    

    【讨论】:

    • 实际上它不起作用 - 结果查询是 ["QUERY_STRING"]=> string(83) "q=domain//" 正如 apache docs 中所述模式最初将与主机名和端口之后的 URL 部分匹配,并且在查询字符串之前(例如“/app1/index.html”)。 似乎应该使用重写映射 -可以单线设置吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-25
    • 1970-01-01
    • 1970-01-01
    • 2016-09-23
    • 2015-04-28
    • 1970-01-01
    • 2015-01-01
    相关资源
    最近更新 更多