.htaccess代码将HTTP请求redirect到HTTPS
我最近把我的网站从HTTP迁移到HTTPS。 我在各种网站上阅读关于使用.htaccess代码将所有HTTP请求redirect到HTTPS。 许多网站提供不同的代码,现在我很困惑我应该使用哪个代码。 以下是在各种网站上find的4个代码: 第一码: RewriteEngine on RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR] RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC] RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC] 第二码: RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] 第三码: RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] 第四码: NameVirtualHost *:80 <VirtualHost *:80> ServerName www.example.com Redirect permanent / https://secure.example.com/ </VirtualHost> <VirtualHost _default_:443> ServerName secure.example.com DocumentRoot /usr/local/apache2/htdocs […]