取消对某些目录WWW站点范围内,力HTTPS和HTTP上的休息吗? [英] Remove www site-wide, force https on certain directories and http on the rest?
问题描述
首先,我想删除了www。从我的域名
Firstly, I would like to remove the www. from my domain name
http://www.example.com =>的 http://example.com
我也想为某些目录是安全(HTTPS),而其余保持HTTP
I would also like for certain directories to be secure (https), while the rest remain http
http://example.com/login =>的 https://example.com/login
显然,这需要工作的所有条件,例如,如果有人类型:
Obviously it needs to work for all conditions, for example if someone types in:
http://www.example.com/login =>的 https://example.com/login
此外,当人们从它返回到http登录页面导航离开。目前在htaccess的是由我使用的软件自动完成下面,我想需要在那里为它工作:
Also when people navigate away from the login page it returns to http. Currently in the .htaccess is the following which is done automatically by the software I am using and I suppose needs to be there for it to work:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php
这是我如何能实现任何想法<打击>梦想控制击>所有这些事情?
Any ideas on how I can achieve dream control all these things?
在此先感谢!
===================
===================
@Gumbo按照你的意见,这是我的完整的.htaccess
@Gumbo Following your advice this is my complete .htaccess
RewriteEngine On
# remove www from host
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(login)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(login)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php
Options -Indexes
导航至的http://例子/登录仍然往的 HTTP://example/index.php 时,应及时到 https://开头例如/登录我是否有顺序错了吗?
Navigating to http://example/login still goes to http://example/index.php when it should go to https://example/login Do I have the order wrong?
推荐答案
请尝试以下规则:
# remove www from host
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(login|foo|bar|…)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force HTTP
RewriteCond %{HTTPS} =on
RewriteRule !^(login|foo|bar|…)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
您可能还需要添加一些附加条件,只更改协议的GET和HEAD请求,但不能在POST请求。
You also might want to add some additional conditions to only change the protocol on GET and HEAD requests but not on POST requests.
这篇关于取消对某些目录WWW站点范围内,力HTTPS和HTTP上的休息吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!