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.

2
  • 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. Commented Jul 5, 2016 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
    Commented Jul 5, 2016 at 12:21

1 Answer 1

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.

5
  • Okay, I added your code and these are the results: i.imgur.com/4QrHJwN.png
    – Beltasbur
    Commented Jul 5, 2016 at 11:00
  • So now it should work fine and redirect to the main URL?
    – Beltasbur
    Commented Jul 5, 2016 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
    Commented Jul 5, 2016 at 12:18
  • I just opened the site (which you could've done yourself) and it redirects
    – Martijn
    Commented Jul 5, 2016 at 12:54
  • Alright, thanks for the help. I appreciate it a lot.
    – Beltasbur
    Commented Jul 5, 2016 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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