Score:0

Apache is not reading .htaccess file

tr flag

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!

kz flag
"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).
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.