Reliably forcing https, my attempts not working

Hello there!

I need two things to happen, one if in the root directory, forward to /forum. Second, if non secure, forward to https. It’s forwarding to forum but only seems to force https if I visit the web root. If I enter http://site.com/forum, it won’t force https in that instance. Here’s my latest attempt:

RewriteEngine On
RewriteRule ^$ /forum [R=301,L,QSD]

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

Code looks good. Should work as is.

Maybe your browser is caching previous attempts? They can be a real pain with caching redirects.

I usually revert to using curl on the command line for these things, as it doesn’t cache 301 responses.

eg

curl -I http://site.com/forum

If that returns a redirect you’ll see something like

HTTP/1.1 301 Found
Location: https://www.site.com/forum
... etc, more headers here ...

The -I in the curl command means you only want to see the headers. That’s enough to debug this issue.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.