htaccess文件未将http子页面重定向到https –而是显示404错误,尝试了许多解决方案,但无济于事

问题描述

我在托管wordpresswordpress站点安装的Google Compute Engine上安装了SSL,一直很难使其完全正常运行。现在,每个站点的主要域都正确重定向到其https版本,并且站点显示它们是安全的,因此它们似乎配置正确。所有链接/图像/等都使用动态URL,因此也可以进行更新。

但是,如果我直接以http形式访问网站的子页面,它将不会重定向到https而是显示404错误(APACHE 404错误,而不是wordpress 404错误)。

如果我手动将https添加到url中,则会正确加载,否则会显示404错误

我倾倒了StackOverflow和StackExchange,并尝试了20种不同的解决方案,但它们都不起作用。最近,我尝试了以下操作:

# Redirect HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

# BEGIN wordpress
# The directives (lines) between `BEGIN wordpress` and `END wordpress` are
# dynamically generated,and should only be modified via wordpress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteRule ^index\.PHP$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.PHP)$ $1 [L]
RewriteRule . index.PHP [L]
</IfModule>

# END wordpress

很遗憾,它无法正常工作。您可以在此处看到我的意思的示例:

http://polararealty.com(将正确重定向到https)
http://polararealty.com/listings/(不会重定向到https,而是显示404错误
https://polararealty.com/listings/显示上面应重定向到的正确页面

有人告诉我,服务器似乎根本没有提供HTTP页面,因此htaccess文件没有任何作用。我对造成这种情况的原因感到困惑。

我使用了本教程来安装SSL:

https://onepagezen.com/free-ssl-certificate-wordpress-google-cloud-click-to-deploy/

解决方法

在我的情况下,答案是我必须访问apache2.conf并将/ var / www /部分中的AllowOverride None调整为All,然后重新启动Apache。在Wordpress.conf,default-ssl.conf等文件中编辑AllowOverride与它无关,必须在apache.conf级别进行。