转换子域URL中的特定URL查询

时间:2014-01-24 11:20:35

标签: regex apache .htaccess mod-rewrite

我想将url的“user”参数中的所有值都带到子域。

即,重定向到URL

http://www.example.com/index.php?user=stackoverflow

http://stackoverflow.example.com/index.php

我有我的私人服务器,我已准备好配置我的apache.conf或任何所需文件,例如.htaccess,以实现我的目标。

请建议。

1 个答案:

答案 0 :(得分:0)

将此代码放入DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^user=([^&]+) [NC]
RewriteRule ^(index\.php)$ http://%1.example.com/$1? [L,NC,R=301]
相关问题