HTTP到HTTPS通过的.htaccess [英] http to https through .htaccess

查看:330
本文介绍了HTTP到HTTPS通过的.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过现有的问题看,但我还没有真正遇到任何事情对我的作品。

I've had a look through existing questions, but I haven't really come across anything which works for me.

目前,我正在运行一个网站,以安全的SSL证书。它可以在 https://www.example.co.uk访问的一个问题,就是在<一个部位,也可访问HREF =htt​​p://www.example.co.uk> http://www.example.co.uk - 我不希望这是可能的。我需要它从HTTP重定向到https。

I'm currently running a site with a Secure SSL certificate. It can be accessed at https://www.example.co.uk a problem is the site can also be accessed at http://www.example.co.uk - I don't want this to be possible. I need it to redirect from http to https.

我发现,code这一个片段中的.htaccess文件中使用。

I found this one snippet of code to use in an .htaccess file.

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^example.co.uk [NC] 
RewriteRule ^(.*)$ https://example.co.uk/$1 [L,R=301]

这工作正常时,用户输入example.co.uk到他们的地址栏,但我还需要添加某种条件语句,所以如果用户输入www.example.co.uk'或'的HTTP ://www.example.co.uk。

This works fine when the user enters example.co.uk into their address bar, but I also need to add a conditional statement of some sort so that if the user enters 'www.example.co.uk' or 'http://www.example.co.uk'.

我使用[OR]的喜欢尝试过,但是这最终建立服务器错误。

I've tried using the likes of [OR], but this ends up creating server errors.

任何帮助和建议,为AP preciated。

Any help and suggestions is appreciated.

干杯。

推荐答案

请尝试以下操作:

 RewriteEngine On
 RewriteCond %{HTTPS} !=on
 RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

另外,你也可以重定向基于端口号,例如:

Also, you can also redirect based on port number, for example:

 RewriteCond %{SERVER_PORT} ^80$
 RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

这将在80端口收到的所有请求重定向到HTTPS。

This will redirect all requests received on port 80 to HTTPS.

这篇关于HTTP到HTTPS通过的.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆