删除整个站点的 www,在某些目录上强制使用 https,在其余目录上强制使用 http?
首先,我想删除www。来自我的域名
http://www.example.com =>; http://example.com
我还希望某些目录是安全的 (https),而其余目录仍然是 http
< a href="http://example.com/login" rel="noreferrer">http://example.com/login => https://example.com/login
显然它需要适用于所有条件,例如,如果有人输入:
http://www.example.com/login =>; https://example.com/login
此外,当人们离开登录页面时,它会返回到 http。目前在 .htaccess 中,以下内容是由我正在使用的软件自动完成的,我想它需要在那里才能工作:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php
关于如何实现梦想控制所有这些事情有什么想法吗?
提前致谢!
===================
@Gumbo 按照您的建议,这是我完整的 .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://example/login 仍然会转到 http://example/index.php 时它应该转到 https://example/login 我的顺序错误吗?
Firstly, I would like to remove the www. from my domain name
http://www.example.com => http://example.com
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
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?
Thanks in advance!
===================
@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
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试这些规则:
您可能还需要添加一些附加条件,以便仅更改 GET 和 HEAD 请求上的协议,而不更改 POST 请求上的协议。
Try these rules:
You also might want to add some additional conditions to only change the protocol on GET and HEAD requests but not on POST requests.
这段代码对我有用:
This code works for me:
删除 www(已测试):
重定向(未测试):
remove www (tested):
redirect (not tested):
阅读完所有帖子时间线后,我成功解决了以下错误:我的网站(c4dprime.com)已附加 https:在 mozilla firefox 浏览器中。 Google 和 internet explore 将域名地址显示为 http: (firefox 中的真正问题) 我不希望在任何浏览器中使用 https: 作为我的域名,因为在安装以下内容后,我的域名通过 https: 附加了一个未知的重定向 (导致此错误) WordPress 中的插件,(ssl 的轻松重定向)....我已经告诉每个人不要使用任何低级别的 WordPress 插件。
反正!通过谷歌搜索引擎阅读了有关该主题的许多文章和教程后。现在我很高兴地说我已经通过这篇文章的提示解决了这个问题。请记住关于我的一件事,我对这种形式和 WordPress 很陌生。
这个技巧对我很有帮助,
在编辑或对我的 .htaccess 文件进行一些更改后,我现在使用的代码解决了这个错误。
After reading this all post time line i have get success for following error: My website(c4dprime.com) was attached https: in mozilla firefox browser. Google and internet explore are show domain address as http: (The real problem in firefox) I did not want https: for my domain in any browser because one unknow redirect attached with my domain by https: (Cause for this error)after Installing following plugins in wordpress,(Easy redirect for ssl).... I have told to every one do not use any low level plugins for wordpress.
Anyway! After reading many articles and tutorials at this topic via google search engine. Now i am happy to say i have solve this problem from this post tips. Remember one thing about me i am new to in this form and wordpress.
This tip is help full for me
After edit or some changes in my .htaccess file following code i have use now with solved this error.