Apache 使用.htaccess rewrite强制https访问

博客首页 » Apache 使用.htaccess rewrite强制https访问

发布于 22 Jun 2014 15:32
标签 blog

.htaccess hosting service

With .htaccess, We can set password restriction to web site.

Basic password

AuthUserFile /home/<user>/.htpasswd
AuthType Basic
AuthName "My Secret Folder"
Require valid-user

With rewrite engine restrict access to https

Shared SSL(https)is provided by almost all hosting service. But private SSL + dedicated IP, which are necessary to get private ssl, needs lots of money. We can use query rewrite it to shared https of hosting service.

RewriteEngine on
RewriteCond %{HTTP_HOST} subdomain.<my domain>
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://<hosting service domain name>/~<user>/host%{REQUEST_URI} [R,L]
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} <my domain>
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://<hosting service domain name>/~<user>%{REQUEST_URI} [R,L]
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

本页面的文字允许在知识共享 署名-相同方式共享 3.0协议和GNU自由文档许可证下修改和再使用,仅有一个特殊要求,请用链接方式注明文章引用出处及作者。请协助维护作者合法权益。



  • Apache 使用.htaccess rewrite强制https访问


rating: 0+x


Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License