无法让 mod_rewrite 停止处理

无法让 mod_rewrite 停止处理

这与当存在其他“子域名”时重写 subdomain.domain.com

我需要 mod_rewrite 来“停止”处理,但它似乎仍在继续。

在我的注册商处,我将 A 记录设置为:

* 12.34.56.78 
@ 12.34.56.78
mgr 12.34.56.79  [it was working, and is working]
dbaccess 12.34.56.79    [this is something new I added]

我的 httpd.conf 现在看起来像这样:

<VirtualHost 12.34.56.79:80>    // notice the 79 which is something I'm trying out!
ServerAlias dbaccess.example.com
DocumentRoot /var/www/html/dbaccess
ServerName dbaccess.example.com
</VirtualHost>

NameVirtualHost 12.34.56.78:80

<VirtualHost 12.34.56.78:80>
ServerAlias *.example.com   // trying to catch science.example.com
DocumentRoot /var/www/html/site
ServerName www.example.com

 <IfModule mod_rewrite.c>
    RewriteEngine On
    ...
    RewriteCond %{HTTP_HOST} ^science\.example\.com [NC]
    RewriteRule (.*) http://www.example.com/classes/science/280.html [R=301,L]

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    ...
</VirtualHost>

// this is needed for other purposes
Listen *:2194

<VirtualHost *:2194>
   Redirect / http://mgr.example.com/
</VirtualHost>

以下是哪些可行,哪些不可行:

http://www.example.com/ works fine
http://mgr.example.com/ works fine
http://science.example.com/ works fine
http://dbaccess.example.com/ does NOT work fine

访问 dbaccess.example.com 会将我重定向到 www.dbaccess.example.com (如果我访问 doesnotexist.example.com 也会重定向到 www.doesnotexist.example.com )

如何让 dbaccess.example.com 显示 /var/www/html/dbaccess 的内容?

答案1

改变:

NameVirtualHost 12.34.56.78:80

NameVirtualHost *:80

确保虚拟主机在两个 IP 接口上都接收请求

答案2

我需要以不同的方式配置一些东西,它变得比必要的更复杂。

我的 A 记录如下:

* 12.34.56.78 
@ 12.34.56.78
mgr 12.34.56.79

I removed:
dbaccess 12.34.56.79

我的 httpd.conf 现在内容为:

// back to original
NameVirtualHost 12.34.56.78:80

<VirtualHost 12.34.56.78:80>
ServerAlias www.example.com science.example.com // change made that works
DocumentRoot /var/www/html/site
ServerName www.example.com

<IfModule mod_rewrite.c>
    RewriteEngine On
    ...
    RewriteCond %{HTTP_HOST} ^science\.example\.com [NC]
    RewriteRule (.*) http://www.example.com/classes/science/280.html [R=301,L]

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    ...
</VirtualHost>

// back to original
<VirtualHost 12.34.56.78:80>
ServerAlias dbaccess.example.com
DocumentRoot /var/www/html/dbaccess
ServerName dbaccess.example.com
</VirtualHost>

Listen *:2194

<VirtualHost *:2194>
   Redirect / http://mgr.example.com/
</VirtualHost>

相关内容