如何使用301重定向而不是302将HTTP站点重定向到HTTPS站点

时间:2014-06-27 08:41:33

标签: wordpress .htaccess mod-rewrite ssl https

我有一个使用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]

1 个答案:

答案 0 :(得分:2)

保持你的.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保留在wordress永久链接设置的主页和网站网址中。

相关问题