Apache-2.4
Apache Virtualhost 將 HTTPS 非 www 重定向到 HTTPS www 不起作用
我遇到了 apache 的問題。我想重定向:
http://www.example.com>到<https://www.example.com - 好的
http://example.com>到<https://www.example.com - 好的
https:// example.com到https://www.example.com - 未重定向
這是我在 Apache 中的 vhost.conf 的設置:
<NameVirtualHost *:80> <VirtualHost *:80> ServerAdmin user@example.com ServerName example.com ServerAlias www.example.com Redirect permanent / https://www.example.com/ DocumentRoot /home/example/public_html ErrorLog /home/example/logs/error.log CustomLog /home/example/logs/access.log combined </VirtualHost> <VirtualHost *:443> ServerAdmin user@example.com ServerName example.com ServerAlias www.example.com RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC] RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301] DocumentRoot /home/example/public_html ErrorLog /home/example/logs/error.log CustomLog /home/example/logs/access.log combined </VirtualHost>
誰能幫我解決這個問題?
我用這個:
RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ %{REQUEST_SCHEME}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
“RewriteCond %{HTTPS} off”無效,因為它已經在埠 443 上