如何解决htaccess文件未将http子页面重定向到https –而是显示404错误,尝试了许多解决方案,但无济于事
我在托管WordPress的WordPress多站点安装的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级别进行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。