Apache-2.2

無法讓 mod_rewrite 停止處理

  • December 30, 2011

當存在其他“子域”時,這與重寫 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 的內容?

我需要以不同的方式配置東西,它變得比必要的複雜得多。

我有以下作為我的 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>

改變:

NameVirtualHost 12.34.56.78:80

NameVirtualHost *:80

確保虛擬主機在兩個 IP 介面上接收請求

引用自:https://serverfault.com/questions/344984