使用htaccess将http网址重定向到https网址 [英] Redirect http url to https url using htaccess

查看:104
本文介绍了使用htaccess将http网址重定向到https网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用htaccess文件中的以下代码将www重定向到非www域,并且要求如下。

I using below code in the htaccess file to redirect www to non www domain and the requirement as below.

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]


RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]

要求


  1. WWW到非WWW

  • http://www.example.com to https://example.com
  • https://www.example.com to https://example.com

非https网址到https网址

  • http://example.com to https://example.com

其他任何非HTTP网址到https网址的页面

  • http://example.com/blog/7-best-places-to-visit to https://example.com/blog/7-best-places-to-visit

结果:


  1. 工作正常。

  1. is working fine as expected.

& 3不起作用,当用户直接在浏览器中输入时仍保留http url。它应该升级到https url。

& 3 is not working and remains http url when user directly enter in browser. It should upgrade to https url.

代码在godaddy共享主机中运行。任何帮助都感激不尽。如有任何问题,请随时让我知道。

Code is running in godaddy shared hosting. Any help will be much appreciated. Please feel free to let me know if any questions.

推荐答案

我用这个:

RewriteEngine On
# the following line is only needed, if HTTP and HTTPS share the same config
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME} !^/.well-known/
RewriteRule .* https://wiimmfi.de$0 [R=301,L]

我排除了 /。众所周知/ 来更新加密证书。

I excluded /.well-known/ to update the let's encrypt certificates.

<目录> 或用于.htaccess:

Inside a <directory> or for .htaccess:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME} !^.well-known/
RewriteRule .* https://wiimmfi.de/$0 [R=301,L]

这篇关于使用htaccess将http网址重定向到https网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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