0

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

示例: http ://example.com/message.php?id=subdomain到http://subdomain.example.com/message.php

这在 .htaccess 中可行吗?

4

1 回答 1

0

这会将所有带有 QUERY_STRING 的 URL(如 id=subdomain 和文件 message.php)重定向到适当的子域:

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 末尾的问号吗?- 它用于禁止附加旧的 QUERY_STRING。我添加了域名检查以避免永久重定向循环的可能性。

于 2013-07-28T13:03:26.310 回答