redirect - WordPress keeps redirecting subpages without http to https homepage after switch

admin2025-01-07  4

I just updated my WordPress site to a full SSL certificate. Everything is working as expected. Only 1 issue I can't solve.

After the update I noticed the homepage is being redirected as expected but subpages are all redirected to the homepage as well.

  • is being redirected to
  • is being redirected to
  • is being redirected to (I would like this to be )

I am using my .htaccess file to get this to work. I think I am missing something.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ %{REQUEST_URI} [NE,L,R]
</IfModule>

I just updated my WordPress site to a full SSL certificate. Everything is working as expected. Only 1 issue I can't solve.

After the update I noticed the homepage is being redirected as expected but subpages are all redirected to the homepage as well.

  • http://www.example.com is being redirected to https://www.example.com
  • http://example.com is being redirected to https://www.example.com
  • http://www.example.com/page is being redirected to https://www.example.com (I would like this to be https://www.example.com/page)

I am using my .htaccess file to get this to work. I think I am missing something.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]
</IfModule>
Share Improve this question edited Nov 2, 2018 at 12:29 MrWhite 3,8911 gold badge20 silver badges23 bronze badges asked Nov 2, 2018 at 11:45 matthijshofstedematthijshofstede 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

You've put the HTTP to HTTPS (and canonical www) redirect in the wrong place. It should go before the WordPress front-controller. In fact, it should go before the # BEGIN WordPress section to avoid any chance of it being overwritten by WordPress in future updates.

To be honest, I'm a bit surprised that redirect would actually do anything (except for requests to static resources)? (Maybe you are seeing a cached redirect, or maybe WP itself is later redirecting to the home page?)

For example:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]

# 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

That redirect should ultimately be a 301 (permanent) redirect. So change R to R=301 once you have confirmed it's working OK.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736255998a325.html

最新回复(0)