Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess根据查询字符串参数重定向到子域_.htaccess_Redirect_Parameters_Subdomain_Query String - Fatal编程技术网

.htaccess根据查询字符串参数重定向到子域

.htaccess根据查询字符串参数重定向到子域,.htaccess,redirect,parameters,subdomain,query-string,.htaccess,Redirect,Parameters,Subdomain,Query String,我需要根据查询字符串设置到子域的重定向 例如: 到 在.htaccess中是否可以这样做?这将把查询字符串(如id=subdomain和file message.php)的所有URL重定向到相应的子域: RewriteEngine on RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC] RewriteCond %{QUERY_STRING} ^id=(.*)$ RewriteRule message.php http://%1.example

我需要根据查询字符串设置到子域的重定向

例如: 到


在.htaccess中是否可以这样做?

这将把查询字符串(如id=subdomain和file message.php)的所有URL重定向到相应的子域:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule message.php http://%1.example.com/message.php? [R=301,L]
注意message.php结尾的问号?-它用于禁止追加旧的查询字符串。我添加了域名检查,以避免永久重定向循环的可能性