使用 htaccess 将所有虚拟子域重写到同一文件夹
我一直在互联网上搜索试图找到解决这个问题的方法,但找不到明确的解决方案。
我正在尝试 redirect 重写
anything.domain.com/anypage.php?sub=anything&include=get_parameters
到
domain.com/users/anypage.php?sub=anything&include=get_parameters
我找到了几个包含可能解决方案的页面,但它们与我的需求略有不同,并且不断编辑它们以失败告终。
任何帮助将不胜感激。谢谢。
PS 通配符 DNS 已启用,并且 apache 中的所有设置均正确。
编辑:
我最终使用了以下内容,它似乎工作得很好。谢谢。
RewriteCond %{HTTP_HOST}
^(.*).domain.com RewriteCond
%{HTTP_HOST} !^www.domain.com [NC]
RewriteRule ^(.*)$
http://domain.com/users/$1?sub=%1 [P]
I have been searching the internet trying to find a solution to this problem but cannot find a definite solution.
I am trying to redirect rewrite
anything.domain.com/anypage.php?sub=anything&including=get_parameters
to
domain.com/users/anypage.php?sub=anything&including=get_parameters
I have found several pages with possible solutions but they all differ slightly to my needs, and editing them continually ends in failure.
Any help would be much appreciated. Thank you.
P.S Wildcard DNS are enabled and everything is set up correctly in apache.
Edit:
I ended up using the folowing, it seems to work pretty well. Thanks.
RewriteCond %{HTTP_HOST}
^(.*).domain.com RewriteCond
%{HTTP_HOST} !^www.domain.com [NC]
RewriteRule ^(.*)$
http://domain.com/users/$1?sub=%1 [P]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的 .htaccess 文件中尝试此规则:
Try this rule in your .htaccess file: