使用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,QSA,L,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
    

要回复问题请先登录注册