我有它使用2個獨立的虛擬主機文件的域:一爲:80,一個用於:443的Apache2重寫規則沒有被拾起
的:80設置是很容易的,這是唯一的工作就是重定向於:443:
<VirtualHost *:80>
# This is the first host so it's the default.
# So although I've specified a ServerName and ServerAlias anything else not specified elsewhere will also end up here.
ServerName www.domain.com
ServerAlias domain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Redirect everything to https:
RewriteEngine on
RewriteRule ^(.*)$ https://www.domain.com$1 [R=301,L]
</VirtualHost>
的:443只需要到www添加到URL的開頭,如果它是不存在的:
<VirtualHost *:443>
# This is the first host so it's the default.
# So although I've specified a ServerName and ServerAlias anything else not specified elsewhere will also end up here.
ServerName www.domain.com
ServerAlias domain.com
ErrorLog ${APACHE_LOG_DIR}/ssl.error.log
CustomLog ${APACHE_LOG_DIR}/ssl.access.log combined
# Redirect everything which is not already on the real www domain name to that:
RewriteEngine on
RewriteCond %{HTTP_HOST} !www.domain.com
RewriteRule ^(.*)$ https://www.domain.com$1 [R=301]
ErrorDocument 404 /404.html
</VirtualHost>
我有1例在這些重複寫似乎忽視:
https://domain.com - >應該指向https://www.domain.com,但它指向https://www.domain.com%24/#。顯然,後面的字符會阻止DNS服務器找到域。
是什麼導致了這個問題?我已經幫助創建了這些虛擬主機文件,但看起來它們仍然沒有像預期的那樣完全工作。
但我也想重寫我的URL到更好的。我想,我的原則是正確的,並在重寫塊:443看起來如下
RewriteEngine on
RewriteCond %{HTTP_HOST} !www.domain.com
RewriteRule ^(.*)$ https://www.domain.com$1 [R=301]
RewriteRule ^subpage/(.+)/?$ subpage.html?$1 [NC]
哪些應該重寫
https://www.domain.com/subpage/2 - >https://www.domain.com/subpage.html?2但它只是指向我的404文件現在。
這可能是明顯的,但我沒有看到我的錯誤。