我在服务器上配置了一个域,将所有请求重定向到我网站的 HTTPS 版本,一切运行正常。几天前,我添加了一个子域,现在它也被重定向到主域。这是迄今为止的 apache 配置文件。
httpd.conf(系统生成,不是我编辑的)
<VirtualHost my.ip:80> ServerName bwdmedia.net ServerAlias bestwebsitedesigners.in bestwebsitedesigners.net bwdmedia.co bwdmedia.org www.bestwebsitedesigners.in www.bestwebsitedesigners.net www.bwdmedia.co www.$ DocumentRoot /home/bwdmedia/public_html ServerAdmin [email protected] UseCanonicalName Off CustomLog /usr/local/apache/domlogs/bwdmedia.net combined CustomLog /usr/local/apache/domlogs/bwdmedia.net-bytes_log "%{%s}t %I .\n%{%s}t %O ." ## User bwdmedia # Needed for Cpanel::ApacheConf UserDir enabled bwdmedia <IfModule mod_suphp.c> suPHP_UserGroup bwdmedia bwdmedia </IfModule> <IfModule !mod_disable_suexec.c> <IfModule !mod_ruid2.c> SuexecUserGroup bwdmedia bwdmedia </IfModule> </IfModule> <IfModule mod_ruid2.c> RMode config RUidGid bwdmedia bwdmedia </IfModule> <IfModule itk.c> # For more information on MPM ITK, please read: # http://mpm-itk.sesse.net/ AssignUserID bwdmedia bwdmedia </IfModule> ScriptAlias /cgi-bin/ /home/bwdmedia/public_html/cgi-bin/ Include "/usr/local/apache/conf/userdata/std/2/bwdmedia/*.conf" </VirtualHost> <VirtualHost my.ip:80> ServerName crm.bwdmedia.net ServerAlias www.crm.bwdmedia.net DocumentRoot /home/bwdmedia/public_html/crm ServerAdmin [email protected] UseCanonicalName Off CustomLog /usr/local/apache/domlogs/crm.bwdmedia.net combined CustomLog /usr/local/apache/domlogs/crm.bwdmedia.net-bytes_log "%{%s}t %I .\n%{%s}t %O ." ## User bwdmedia # Needed for Cpanel::ApacheConf UserDir enabled bwdmedia <IfModule mod_suphp.c> suPHP_UserGroup bwdmedia bwdmedia </IfModule> <IfModule !mod_disable_suexec.c> <IfModule !mod_ruid2.c> SuexecUserGroup bwdmedia bwdmedia </IfModule> </IfModule> <IfModule mod_ruid2.c> RMode config RUidGid bwdmedia bwdmedia </IfModule> <IfModule itk.c> # For more information on MPM ITK, please read: # http://mpm-itk.sesse.net/ AssignUserID bwdmedia bwdmedia </IfModule> ScriptAlias /cgi-bin/ /home/bwdmedia/public_html/crm/cgi-bin/ Include "/usr/local/apache/conf/userdata/std/2/bwdmedia/*.conf" </VirtualHost>
cp_php_magic_include_path.conf(上一个 VirtualHost 末尾的包含文件
ServerName www.bwdmedia.net ServerAlias bwdmedia.co bwdmedia.org www.bwdmedia.co www.bwdmedia.org bwdmedia.net Redirect 301 "/" "https://bwdmedia.net/"
我尝试访问crm.bwdmedia.net
,但被重定向到https://bwdmedia.net
。如果我注释掉第 2 点中的 3 行,子域名就会开始工作。所以问题出在这里。有什么想法吗?
答案1
使用 RewriteCond 匹配除 example.com 之外的域并对其进行 301 重定向:
RewriteEngine On
# If the domain (any domain) is not exactly example.com...
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule (.*) http://example.com/$1 [L,R=301,QSA]
您还可以更具体地查找 example.com 的子域名。上面的子域名将与任何其他域名匹配。
# Match only subdomains of example.com
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteRule (.*) http://example.com/$1 [L,R=301,QSA]