Apache 使用.htaccess rewrite强制https访问

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

发布于 13 Apr 2014 01:43
标签 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