302 redirect instead of 301 after switch to HTTPS

Last week I changed my website from HTTP to HTTPS.

Despite the 301 redirect rule in .htaccess, all old (HTTP) pages are redirected with a 302 redirect for some reason. I cannot find what this is and did not change any plugins at all. The only thing I created was an extra rule in .htaccess. Website url = https://www.janjippe.nl/

Here is an overview of my .htaccess file:

#BEGIN WordPress
<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{HTTPS} !=on
RewriteCond %{SERVER_PORT} ^80$
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

However, currently, I only see 302 redirects when checking all the pages.
How can I make sure that a 301 redirect will be in place instead of a 302 redirect?

This matters for the private_html folder.

The public_html folder is empty with the exception of 1 .htaccess file containing the following content:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.janjippe.nl/$1 [R,L]

<IfModule mod_headers.c>
  Header set Strict-Transport-Security "max-age=31536000"
</IfModule>

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

AddDefaultCharset UTF-8

RewriteCond %{HTTP_HOST} ^janjippe.nl
RewriteRule ^(.*)$ http\:\/\/www\.janjippe\.nl\/$1 [R=301,L]

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/all/$1/index.html -f [or]
RewriteCond /home/janjikm99/domains/janjippe.nl/public_html/wp-content/cache/all/$1/index.html -f
RewriteRule ^(.*) "/wp-content/cache/all/$1/index.html" [L]
</IfModule>

<FilesMatch "\.(html|htm)$">
  FileETag None

  <ifModule mod_headers.c>
  Header unset ETag
  Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
  Header set Pragma "no-cache"
  Header set Expires "Mon, 29 Oct 1923 20:30:00 GMT"
  </ifModule>
</FilesMatch>

# 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

1 Answer
1

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.janjippe.nl/$1 [R,L]

Your “old” .htaccess file at /public_html/.htaccess would appear to have the suspect 302 redirect. Without an explicit status code, the R flag defaults to a 302.

If the entire site has been moved to the /private_html folder as part of the implementation of SSL then it would seem that HTTP (port 80) is served from /public_html and HTTPS (port 443) is served from /private_html! (A bit of a strange setup as this would allow you to (accidentally) serve different content for each – which would be a bad idea.)

If this is the case then you could probably change the old /public_html/.htaccess file to simply read:

Redirect 301 / https://www.example.com/

And potentially remove the HTTP to HTTPS redirect in the /private_html/.htaccess file, since this new site (in /private_html) would seem to only be accessed over HTTPS anyway! However, it might be preferable to keep this redirect in place “just in case” there is any change in configuration.

(Note: It can be easier to first test with temporary 302 redirects since these are not cached. If an erroneous redirect is cached then it can be confusing to debug.)

Leave a Comment