将主机名包含在mod_rewrite RewriteRule中

时间:2013-02-11 14:08:24

标签: .htaccess mod-rewrite

我在一个虚拟主机中有多个域,例如别名: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]

UPDATE1

尝试使用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服务器错误而崩溃:(

1 个答案:

答案 0 :(得分:0)

尝试

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