使用 .htaccess 重定向所有页面时,我的代码发生冲突

While redirecting all pages with .htaccess my codes are conflicting

我正在尝试重定向到

https://example.com from https://www.example.com, http://example.com, http://www.example.com

----------------和----------------

https://example.com/sub_page/pages from https://www.example.com/sub_page/pages, http://example.com/sub_page/pages, http://www.example.com/sub_page/pages

在 .htaccess 上,但我的 sub_pages 没有正确重定向。可能是因为下面的代码冲突。我在网上看了很多文章,但没有找到有用的东西。

my .htaccess file

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule ^(.*)$ https://example.com/ [R=301,L]

我想你明白我的意思了。简而言之,我想重定向所有请求 到非=www和https。请帮助我,

这可能就是您要找的:

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]

这应该可以在实际的 http 服务器配置中工作,或者,如果您无法访问它,则可以在位于 http 主机的文档根目录中的分布式配置文件 (".htaccess) 中工作。