I'm trying to redirect all insecure HTTP requests on my site (e.g. http://www.example.com
) to HTTPS (https://www.example.com
). I'm using PHP btw. Can I do this in .htaccess?
相关问题
- Angular RxJS mergeMap types
- Backbone.js PushState routes .htaccess only workin
- “Zero out” sensitive String data in Swift
- Stop .htaccess redirect with query string
- Stop .htaccess redirect with query string
相关文章
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
- 请大神帮忙 post向https接口发送数据 部署到服务器为什么运行一会后就会报空指针
- How to get jQuery.ajax response status?
- send redirect and setting cookie, using laravel 5
- Warning : HTML 1300 Navigation occured?
- Is a unicode user agent legal inside an HTTP heade
- git: retry if http request failed
- Security concerns about CORS
Through .htaccess This will help.
Also, Refer this for More Detail. How To Redirect Http To Https?
If you are using Apache, mod_rewrite is the easiest solution, and has a lot of documentation online how to do that. For example: http://www.askapache.com/htaccess/http-https-rewriterule-redirect.html
The best solution depends on your requirements. This is a summary of previously posted answers with some context added.
If you work with the Apache web server and can change its configuration, follow the Apache documentation:
But you also asked if you can do it in a
.htaccess
file. In that case you can use Apache's RewriteEngine:If everything is working fine and you want browsers to remember this redirect, you can declare it as permanent by changing the last line to:
But be careful if you may change your mind on this redirect. Browsers remember it for a very long time and won't check if it changed.
You may not need the first line
RewriteEngine On
depending on the webserver configuration.If you look for a PHP solution, look at the $_SERVER array and the header function:
This is the html redirect approach it works but not the best.
PHP approach
.htaccess approch
copied from: www.letuslook.org
The Apache docs recommend against using a rewrite:
This snippet should go into main server configuration file, not into
.htaccess
as asked in the question.This article might have come up only after the question was asked and answered, but seems to be the current way to go.
I found a method to force all pages of my site redirect from http to analog of pages on https that work for me.