如何解决使用htaccess将所有虚拟子域重写到同一文件夹
|| 我一直在互联网上搜索,试图找到解决此问题的方法,但是找不到确切的解决方案。 我正在尝试重定向重写 any.domain.com/anypage.php?sub=anything&include=get_parameters 至 domain.com/users/anypage.php?sub=anything&include=get_parameters 我找到了几页提供可能解决方案的页面,但是它们与我的需求略有不同,并且不断对其进行编辑会以失败告终。 任何帮助将非常感激。谢谢。 P.S通配符DNS已启用,并且所有内容均已在apache中正确设置。 编辑: 我最终使用了以下方法,看来效果很好。谢谢。RewriteCond %{HTTP_HOST}
^(.*).domain.com RewriteCond
%{HTTP_HOST} !^www.domain.com [NC]
RewriteRule ^(.*)$
http://domain.com/users/$1?sub=%1 [P]
解决方法
在您的.htaccess文件中尝试以下规则:
Options +FollowSymLinks
RewriteEngine on
# redirect for http
RewriteCond %{HTTP_HOST} !^www\\.domain\\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\\.domain\\.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*)$ http://domain.com/users/$1?sub=%1 [R=301,QSA,L,NE]
# redirect for https
RewriteCond %{HTTP_HOST} !^www\\.domain\\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\\.domain\\.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^(.*)$ https://domain.com/users/$1?sub=%1 [R=301,NE]
R=301 will redirect with https status 301
L will make last rule
NE is for no escaping query string
QSA will append your existing query parameters
$1 is your REQUEST_URI
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。