简体   繁体   English

如何将我的所有网站帖子/页面从 Http(+ www 或非 www)重定向到 Https(非 www)URL

[英]How to redirect all my website posts/pages from Http (+ www or non-www) to Https (non-www) URL

I recently updated my website from http to HTTPS & I don't have any prior knowledge about this.我最近将我的网站从 http 更新到 HTTPS 并且我对此一无所知。 I did it following some articles on the internet & it was successful.我是按照互联网上的一些文章进行的,并且很成功。 My site is accessible through https & it's all fine.我的网站可以通过 https 访问,一切都很好。

But I'm stuck with redirecting the existing pages and posts.但我坚持重定向现有的页面和帖子。 I'm not sure if I messed it up or I just don't know how to redirect properly.我不确定我是否搞砸了,或者我只是不知道如何正确重定向。

Here's what I'm trying to do, I want to redirect all the URLs in the below format to redirect这是我正在尝试做的事情,我想重定向以下格式的所有 URL 以重定向

from:从:

to

I've tried using the following code, but it's not helping.我试过使用下面的代码,但它没有帮助。

# Canonical https/www
<IfModule mod_rewrite.c>
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
    RewriteRule (.*) https://www.%1/$1 [R=301,L]
</IfModule>

Any help would be appreciated.任何帮助,将不胜感激。 Thanks a lot in advance.提前非常感谢。

Found the answer after carefully doing some troubleshooting.仔细做了一些故障排除后找到了答案。 The issue is with ReallySimple SSL plugin I used while updating to https.问题在于我在更新到 https 时使用的真正简单的 SSL 插件。

By default, the plugin is redirecting all the traffic to https://www.example.com format which is showing an error page.默认情况下,插件将所有流量重定向到https://www.example.com格式,该格式显示错误页面。

So I made the changes as per my requirement.所以我根据我的要求进行了更改。

The problem is I didn't notice that this code exists & I'm looking at a wrong htaccess file in root folder instead of the htaccess file in public_html file.问题是我没有注意到此代码存在并且我正在查看根文件夹中的错误 htaccess 文件,而不是 public_html 文件中的 htaccess 文件。

# BEGIN rlrssslReallySimpleSSL rsssl_version[3.3.1]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://example.com%{REQUEST_URI} [R=301,L]
</IfModule>

I hope this is helpful if someone faces similar issue.如果有人遇到类似问题,我希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM