.htaccess重定向子域

时间:2012-01-04 17:21:29

标签: .htaccess

我想允许用户输入

xyz.example.com

为了达到

test.php?id=xyz

我应该用什么代码来实现我的目标?

1 个答案:

答案 0 :(得分:1)

尝试将以下内容添加到example.com域根目录中的htaccess文件

RewriteEngine on
RewriteBase /

#if the host is anything.example.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
#send all requests to test.php
RewriteRule .* test.php?id=%1 [L]
相关问题