2

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
  • How was the SSL implemented? Did you install an SSL cert directly on your application server? You shouldn't need to check both %{HTTPS} !=on and %{SERVER_PORT} ^80$ (although that's not necessarily related to this problem). – MrWhite Sep 1 '17 at 14:32
  • The SSL whas implemented automatically by hosting party (Versio NL). So I didn't need to install anything. – Marc Sep 1 '17 at 14:39
  • - What's the URL so I can see the redirects? - Also, do you have a .htaccess "higher up" above the one you've quoted here. - Is this all that's inside your .htaccess, or could there be other redirects from other plugins inserted into your .htaccess? – Paul G. Sep 1 '17 at 15:04
  • There are no other redirect plugins installed on the website. One thing, in the FTP client I used to work with a folder public_html. Now with HTTPS I received a new folder called private_html (which contains the website). The public_html has got no content, but only a .htaccess file. My complete .htaccess file is the following – Marc Sep 1 '17 at 15:55
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.)

  • If your setup it as it appears to be (a separate place on the filesystem for the HTTPS-only site) then you can probably even remove the HTTP to HTTPS redirect from your "new" HTTPS site (although that is probably more theoretical, rather than practical). I've updated my answer. – MrWhite Sep 1 '17 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.