使用htaccess将http网址重定向到https网址

编程入门 行业动态 更新时间:2024-10-23 07:34:38
本文介绍了使用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\$ RewriteRule ^/?$ "https\:\/\/example\\/" [R=301,L] RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^www\.example\$ RewriteRule ^/?$ "https\:\/\/example\\/" [R=301,L]

要求:

  • WWW到非WWW

    • www.example 到 example
    • www.example 到 example
    • www.example to example
    • www.example to example

    非https网址到https网址

    • example 到 example
    • example to example

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

    • example/blog / 7-best-places-to-visit 到 https:/ /example/blog/7-best-places-to-visit
    • example/blog/7-best-places-to-visit to example/blog/7-best-places-to-visit

    结果:

  • 工作正常。

  • 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 .* 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 .* wiimmfi.de/$0 [R=301,L]
  • 更多推荐

    使用htaccess将http网址重定向到https网址

    本文发布于:2023-10-31 12:59:33,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1546155.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:网址   重定向   htaccess   http   https

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!