apache 将 http 重定向到 https,将 www 重定向到非 www

编程入门 行业动态 更新时间:2024-10-23 21:30:19
本文介绍了apache 将 http 重定向到 https,将 www 重定向到非 www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

基本上我想要的是重定向请求以使用 HTTPS 而不是 http

basically what i want is redirect al request to use HTTPS instead of http

到目前为止,我的 htaccess 中有这个,而且效果很好:代码:

I have this in my htaccess so far and it worked great: Code:

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) %{HTTP_HOST}%{REQUEST_URI} </ifModule>

今天有人注意到,当去:www.example 它重定向到并显示不安全的连接内容.

today someone noticed that when going to: www.example it redirects to and shows an unsecure connection thingie.

我的 ssl 是为非 www 域设置的:mydomain

My ssl is setup for non www domain: mydomain

所以我需要确保所有站点请求都发送到非 www 和 https:如果我把 example 它重定向到 example

So i need to make sure all site requests are sent to non www and https: It works fine if i put example it redirects to example

但是对于 www.example,它转到 htts://www.example 并显示错误

but with www.example it goes to htts://www.example and shows the error

我需要在代码中添加什么才能将 www 重定向到非 www 然后重定向到 ssl?

what do i need to add to my code to redirect www to non www and then to ssl ?

推荐答案

你可以从 HTTP_HOST 得到你需要的

You can get what you need from the HTTP_HOST

RewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^(?:www.)?(.*)$ [NC] RewriteRule (.*) %1%{REQUEST_URI} [L,R=301]

这样它就会让主机始终没有子域.

This way it will get the host always without the subdomain.

更多推荐

apache 将 http 重定向到 https,将 www 重定向到非 www

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

发布评论

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

>www.elefans.com

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