I want my website to always show "https://www.example.com." If a user clicks a URL in a different format, it must redirect to the full URL with "www" and "https."
I tried to force my WordPress website to always use "https" by updating the .htaccess file. I found that the redirection works for most cases, but some URLs, like "http://example.com/category," don't redirect properly.
However, if I add a trailing slash to the URL, like "http://example.com/category/," the redirect rule works as expected.
Below is my .htaccess code. My website is hosted on Cloudways.
# BEGIN WordPress<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC] RewriteCond %{HTTP:X-Forwarded-Proto} !https 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