I'm having trouble getting an .htaccess file to work on my self-hosted server. I'm trying to redirect all visitors to HTTPS and non-www using the following directives:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
However, I've added some random text to the beginning of the .htaccess file to check if it's being read by Apache, and it didn't cause an error when accessing my website, so it seems like the file isn't being read.
Here are the steps I've already taken:
- Checked that the .htaccess file is in the correct directory.
- Checked the file permissions for the .htaccess file.
- Verified that the mod_rewrite module is enabled in the Apache configuration.
- Checked the Apache error logs, but didn't find any relevant errors.
- Made sure that the AllowOverride directive is set to All in my Apache configuration file.
I'm running Ubuntu 22.04
Any help or suggestions would be greatly appreciated. Thank you!