How can I fix 302 Found error?

July 4, 2016 16k views
Apache Server Optimization Ubuntu 16.04

Hello there,

My some end-users getting 302 Found response page while trying to access my forum, which is powered by Invision Power Suite. I tried to troubleshoot with CURL about what is the problem, these are the results:

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

It seems, my server is giving 302 response everytime user tries to access it through non-SSL. I don't want to give up from security, so I have to find a way without disabling SSL.

HSTS is enabled, and my forum uses HTTPS address as the main board URL. I couldn't find a proper solution in the internet, so I wanted to ask DigitalOcean community.


Note: Apache is 2.4.20, PHP is 7.0.8 (both from packages) and MySQL is 5.7.12 (Ubuntu packages)

1 Answer

Can you clarify what the problem you're running into is? A 302 response is a redirect. If you wish to use HTTPS for your site then this is a proper configuration. Having responses for http being a 302 redirect to the HTTPS version of the site rather than allowing browsing insecurely.

  • I think I fixed the problem. I added this code to .htaccess file:

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

    The result was like this:

    So it now successfully redirects my users to the website itself, I think this will do just fine for me.

Have another answer? Share your knowledge.