2

I host a forum website in DigitalOcean's cloud servers, using Ubuntu 16.04, Apache 2.4.20, PHP 7.0.8 and MySQL 5.7.12.

I tried to troubleshoot with cURL about what is the problem, these are the results:

enter image description here

And this is the .htaccess of the root directory (/var/www/html/)

enter image description here

HSTS is enabled, and my forum uses HTTPS address as the main board URL.

  • A 302 response requires a Location: header. You have somehow configured your server to respond with that status, but without the header. The lack of the redirect location is the problem. – Stephen Ostermiller Jul 5 '16 at 10:40
  • @StephenOstermiller Since the L flag is missing on the RewriteRule, the request will be (internally) rewritten again, which I guess is probably messing up the redirect (ie. absent Location: header). (?) – MrWhite Jul 5 '16 at 12:21
1

I suggest you add [R=301,L] after your RewriteRule in your .htaccess to redirect the visitor, like so:

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Currently your telling the browser "There is a https version I want you to visit". The R=301 adds "I want you to go there via a 301 reload". It's the reload part you don't have in place currently.
The L stands for "Last", after this line it will not excecute the remainder of your htaccess, it will start the reload. After the reload this line is skipped.

  • Okay, I added your code and these are the results: i.imgur.com/4QrHJwN.png – Beltasbur Jul 5 '16 at 11:00
  • So now it should work fine and redirect to the main URL? – Beltasbur Jul 5 '16 at 11:01
  • 1
    Apache will implicitly do a 302 redirect when specifying an absolute URL in the RewriteRule substitution. However, because the L flag is missing the request is being rewritten (again) and "messing up" the redirect. (But yes, a 301, rather than a 302, should be used for such redirects anyway.) – MrWhite Jul 5 '16 at 12:18
  • I just opened the site (which you could've done yourself) and it redirects – Martijn Jul 5 '16 at 12:54
  • Alright, thanks for the help. I appreciate it a lot. – Beltasbur Jul 5 '16 at 14:13

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.