0

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!

RAD6000
  • 113
  • 3
  • "Made sure that the AllowOverride directive is set to All in my Apache configuration file." - But where exactly? This is most likely to be the cause of the problem. Note that `AllowOverride None` should be set for the root directory (in the main Apache config) and only overridden for the specific directory in question (usually in a vHost container). – MrWhite Mar 03 '23 at 21:55

0 Answers0