[英]redirect from non-www domain name to www using virtualhost not working
我在將http://domain.co.uk重定向到http://www.domain.co.uk時遇到問題。 我對使用apache和linux很陌生,所以這是我到目前為止所做的。 希望有一個顯而易見的錯誤可以輕松解決。
在嘗試使重定向正常工作的過程中,我發現一些教程說應該通過virtualhost文件執行此操作,因此我編輯了最初為該站點設置的現有虛擬主機文件。
/etc/apache2/sites-available/domain.co.uk
我在該文件的頂部添加了一個新塊,因此現在看起來像這樣:
<VirtualHost *:80>
ServerName domain.co.uk
Redirect permanent / http://www.domain.co.uk/
</VirtualHost>
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin admin@domain.co.uk
ServerName www.domain.co.uk
ServerAlias domain.co.uk
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/simon/public/domain.co.uk/public/
# Log file locations
LogLevel warn
ErrorLog /home/simon/public/domain.co.uk/log/error.log
CustomLog /home/simon/public/domain.co.uk/log/access.log combined
</VirtualHost>
編輯此文件后,我重新啟動了Apache並嘗試了該站點,但http://domain.co.uk卻給我“無法打開頁面-無法訪問服務器”。 http://www.domain.co.uk仍然可以正常工作。
這是<virtualhost>
塊的正確位置嗎? 我已經看到有人提到將虛擬主機信息放入httpd.conf
文件中,但是在安裝apache時找不到該文件。
任何幫助都會很棒。
試試這個並重啟Apache
<VirtualHost *:80>
ServerName domain.co.uk
ServerAlias *.domain.co.uk
RedirectMatch permanent /(.*) http://www.domain.co.uk/$1
</VirtualHost>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.