我在測試VPS上運行了幾十個站點,並且當前使用mod_vhost_alias來避免每次拋出新站點時都需要新的VirtualHost。我目前的配置如下:使用fall_through重寫mod_vhost_alias
<VirtualHost *:80>
ServerName my.servername.com
ServerAlias *
VirtualDocumentRoot /var/www/%0/public_html
</VirtualHost>
在我的/ var/www目錄中,每個站點都有自己的目錄。例如,我個人頁面的路徑是/var/www/personalsite.com/public_html/index.php。這對於http://personalsite.com的請求非常有用。
但是,當請求進入http:// www .personalsite.com時,這不起作用。對於我的一些其他網站,我有相反的問題 - 目錄可能是/var/www/www.sitename.com/public_html,所以請求http://www.sitename.com罰款。但是,請求http://sitename.com不起作用。
有沒有辦法設置我的Apache配置,以便當請求進來時,它執行以下操作?這樣做會有什麼性能影響嗎?
僞代碼:
1. Check if the directory or file exists. If it does, skip the rest of the rules
(but don't stop, in case a local .htaccess has rules in it for pretty URLs
in WordPress or Concrete5)
2. If the file/directory does not exist:
1. If the host header starts with "www":
1. remove the www from the host header and try the first rule again.
2. If the host header does not start with "www":
1. add "www" to the beginning of the host header and try the first rule again
3. If it still fails after trying both conditions:
1. Go to a 404 error page
我目前有大約20 virtualhosts這樣做,但似乎可笑,當我必須添加爲每個站點一個新的。使用mod_vhost_alias的意義在於避免首先需要所有這些VirtualHost。
感謝您的答案,但我不認爲這完全解決了我想要做的。我的目標之一是沒有每個網站的虛擬主機。我已經重寫了我想要僞代碼的內容,並更新了問題。這是否更有意義? – CristosLC