【问题标题】:How to redirect a HTTP site to HTTPS site using 301 redirect instead of 302如何使用 301 重定向而不是 302 将 HTTP 站点重定向到 HTTPS 站点
【发布时间】:2014-08-18 07:26:20
【问题描述】:

我有一个使用 https 的 woocommerce 网站。如果使用 302 重定向重定向 https,我需要将其更改为 301 重定向。我在结帐页面上有“强制 SSL (HTTPS)(需要 SSL 证书)”。在 woo Commerce 设置中检查了选项,我的 htaccess 文件在下面

从 302 重定向到 301 重定向的最佳方式是什么?

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# Forcing HTTPS
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.aransweatersdirect.com/$1 [R,L]

【问题讨论】:

  • 谷歌搜索“apache 301 重定向”时的第一个命中是this,它看起来描述了您需要的内容。

标签: wordpress .htaccess mod-rewrite ssl https


【解决方案1】:

确保在默认 WP 规则之前保留 http-&gt;https 重定向规则,该规则将每个 URI 重写为 index.php

保持你的 .htaccess 像这样:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

# END WordPress

然后确保将https 保留在您的主页和站点 URL 的 wordress 永久链接设置中。

【讨论】:

  • 你能解释一下问题作者没有的那些行吗?它也对我有用,但我想了解它为什么有效以及是什么原因造成的。
  • 我添加了有问题的
猜你喜欢
  • 1970-01-01
  • 2018-05-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-11
  • 1970-01-01
  • 2018-02-28
  • 2019-04-12
  • 2014-10-02
相关资源
最近更新 更多