几个月前,我将客户网站从旧的旧版CMS迁移到Wordpress。许多网址发生了变化,我在301.htaccess中重定向 - 一切似乎都很好。这都是http,没有https,这让我感到...
今天,我将客户端迁移到https并遇到重定向问题。这些旧网址现在通过2次重定向,一次将网址更改为https,然后再次转到新网站网址。我不确定如何设置.htaccess文件,以便那些旧网站的http网址直接转到新网站https网址,而不需要中间步骤。
我已经读过这个问题可能是我混淆了重写和重新指导。我想知道是否也涉及Wordpress重写位。
这是我所拥有的,只有2个示例网址,以尽可能简短。我在#之后添加了评论,试着解释我的想法:
Options +FollowSymLinks
RewriteEngine on
# these two lines, I hoped, would redirect from the previous site's http URL to the new site's https URL - but in practice, it is being ignored and it seems to skip to the site-wide rule below it
Redirect 301 /page1 https://www.example.com/folder/page1/
Redirect 301 /page2 https://www.example.com/folder/page2/
# this is the site-wide re-write of new site non-https requests to https - this works fine
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# This is the standard Wordpress rules, this might be impacting what I'm trying to do
# 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
我希望我很清楚自己要做什么。我认为解决方案是使用所有重写,并按正确的顺序,可能在Wordpress位内?
提前感谢您的帮助。
吉姆
编辑(抱歉试图将其放入评论中)。根据有用的建议,我现在有了这个:
这就是我现在正在做的事情:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off
RewriteRule ^/page1$ https://%{HTTP_HOST}/folder/page1/ [R=301,L]
RewriteRule ^/page2$ https://%{HTTP_HOST}/folder/page2/ [R=301,L]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
但是这一行:RewriteRule(。*)https://% {HTTP_HOST}%{REQUEST_URI} [R = 301,L]无法将任何其他网址重定向到https