.htaccess基于查询字符串参数重定向到子域 [英] .htaccess redirect to subdomain based on query string parameter
本文介绍了.htaccess基于查询字符串参数重定向到子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要根据查询字符串设置到子域的重定向.
I need to set up a redirection to sub domain based on query string.
示例: http://example.com/message.php?id=subdomain 到 http://subdomain.example.com/message.php
.htaccess中有可能吗?
Is this possible in .htaccess?
推荐答案
这会将所有带有QUERY_STRING的URL重定向,例如id = subdomain和文件message.php到相应的子域:
This will redirect all the URLs with QUERY_STRING like id=subdomain and file message.php to the appropriate subdomain:
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.我添加了域名检查以避免永久重定向循环的可能性.
Mind the question mark at the end of message.php? - it is used to suppress appending the old QUERY_STRING. I added the domain name check to avoid the possibility of eternal redirect loop.
这篇关于.htaccess基于查询字符串参数重定向到子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文