Htaccess 文件没有将 http 子页面重定向到 https——它们显示 404 错误,尝试了很多解决方案并且 none 有效
Htaccess file isn't redirecting http sub-pages to https––they display 404 error instead, tried many solutions and none work
我在 Google Compute Engine 托管的 WordPress 多站点安装上安装了 SSL,但一直很难让它完全正常工作。现在,每个站点的主域都正确重定向到它们的 https 版本,并且站点显示它们是安全的,因此它们似乎配置正确。所有 links/images/etc 使用动态 URL,因此它们也可以正常更新。
但是,如果我以 http 形式直接访问站点的子页面,它不会重定向到 https,而是显示 404 错误(APACHE 404 错误,而不是 WordPress 404 错误)。
如果我手动将 https 添加到 url,它会正确加载,否则只会显示 404 错误。
我研究了 Whosebug 和 StackExchange,尝试了大约 20 种不同的解决方案,其中 none 有效。最近我尝试了以下方法:
# 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).*) [L]
RewriteRule ^(.*\.php)$ [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 调整为全部,然后重新启动 Apache。在 Wordpress.conf、default-ssl.conf 等中编辑 AllowOverride 对此没有任何影响,必须在 apache.conf 级别完成。
我在 Google Compute Engine 托管的 WordPress 多站点安装上安装了 SSL,但一直很难让它完全正常工作。现在,每个站点的主域都正确重定向到它们的 https 版本,并且站点显示它们是安全的,因此它们似乎配置正确。所有 links/images/etc 使用动态 URL,因此它们也可以正常更新。
但是,如果我以 http 形式直接访问站点的子页面,它不会重定向到 https,而是显示 404 错误(APACHE 404 错误,而不是 WordPress 404 错误)。
如果我手动将 https 添加到 url,它会正确加载,否则只会显示 404 错误。
我研究了 Whosebug 和 StackExchange,尝试了大约 20 种不同的解决方案,其中 none 有效。最近我尝试了以下方法:
# 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).*) [L]
RewriteRule ^(.*\.php)$ [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 调整为全部,然后重新启动 Apache。在 Wordpress.conf、default-ssl.conf 等中编辑 AllowOverride 对此没有任何影响,必须在 apache.conf 级别完成。