I'm running macOS 10.15 (Catalina) and have installed the latest Apache (2.4.43) using brew
, basically following these steps.
It seems to be working OK, I can visit http://localhost/ and when I change /usr/local/etc/httpd/httpd.conf
(e.g. different port, different DocumentRoot, etc) and sudo apachectl restart
, the changes are reflected in my local webserver.
However I also uncommented this line in httpd.conf
:
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
But putting a .htaccess
file in my DocumentRoot and defining some RewriteRules there does not seem to have any effect. Already did sudo apachectl restart
but no difference.
mod_rewrite.so
seems to be present, that is assuming that lib/httpd/modules/
in my httpd.conf
refers to /usr/local/lib/httpd/modules
.
Am I doing something wrong? How do I enable mod_rewrite?
(edit) as reference, here are my .htaccess
contents:
DirectoryIndex index.php index.html
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule test index.html [R=301,L,QSA]
I can visit
http://localhost:8080/index.html
, that works fine. ✅When visiting
http://localhost:8080/
I get the directory index (list of files), not the index.html page as I would expect from theDirectoryIndex
line. ❌When visiting
http://localhost:8080/test
I get 'Not Found', not the index.html page as I would expect from theRewriteRule
. ❌
(edit2) For what it's worth, if I do apachectl -t -D DUMP_MODULES
it shows a list of loaded modules and it includes rewrite_module
.
sudo apachectl -k restart
says "httpd: illegal option -- k". Tried without-k
, and also triedsudo apachectl stop
and thensudo apachectl start
separately. But still no difference.sudo apachectl -v
it says2.4.43
i.e. the version I installed withbrew
(withoutsudo
same result by the way). Is there a way to be sure?which apachectl
tells me/usr/local/bin/apachectl
.