Apache自动跳转到 HTTPS

《Apache自动跳转到 HTTPS》要点:
本文介绍了Apache自动跳转到 HTTPS,希望对您有用。如果有疑问,可以联系我们。

Apache自动跳转到 HTTPS

网站根目录新建 .htaccess

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

301跳转

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteBase /

RewriteCond %{SERVER_PORT} !^443$

RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L]

</IfModule>

站点绑定多个域名,只允许www.gworg.com 跳转

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteCond %{HTTP_HOST} ^example.com [NC,OR]

RewriteCond %{HTTP_HOST} ^www.example.com [NC]

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

###把网址更改为自己的###

高级用法 (可选)

RewriteEngine on

# 强制HTTPS

RewriteCond %{HTTPS} !=on [OR]

RewriteCond %{SERVER_PORT} 80

# 某些页面强制

RewriteCond %{REQUEST_URI} ^something_secure [OR]

RewriteCond %{REQUEST_URI} ^something_else_secure

RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

# 强制HTTP

RewriteCond %{HTTPS} =on [OR]

RewriteCond %{SERVER_PORT} 443

# 某些页面强制

RewriteCond %{REQUEST_URI} ^something_public [OR]

RewriteCond %{REQUEST_URI} ^something_else_public

RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

《Apache自动跳转到 HTTPS》是否对您有启发,欢迎查看更多与《Apache自动跳转到 HTTPS》相关教程,学精学透。编程之家PHP学院为您提供精彩教程。

相关文章

1、到apache官网上下载apache的安装文件 http://httpd.apache.org/download.cgi 点击链接Files for Mic...
1.确保apache已开启rewrite。 2.在.htaccess文件中添加如下: RewriteEngine On RewriteCond %{HTTP_RE...
在httpd.conf中修改ErrorLog和CustomLog的配置 ErrorLog &quot;|E:/apache2.2/bin/rotatelogs.exe ...
1、打开apache的配置文件httpd.conf,打开如下项 LoadModule proxy_module modules/mod_proxy.so LoadM...
一、下载必须的安装源码包 http://httpd.apache.org/download.cgi#apache24 httpd-2.4.23.tar.gz http:...
1.在apache配置文件httpd.conf中找到如下行: #LoadModule rewrite_module modules/mod_rewrite.so 去掉...