2

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]
  1. I can visit http://localhost:8080/index.html, that works fine. ✅

  2. When visiting http://localhost:8080/ I get the directory index (list of files), not the index.html page as I would expect from the DirectoryIndex line. ❌

  3. When visiting http://localhost:8080/test I get 'Not Found', not the index.html page as I would expect from the RewriteRule. ❌


(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.

8
  • @klanomath How do you mean properly configure? I've edited my post and added the .htaccess contents + some test results.
    – RocketNuts
    Commented Apr 13, 2020 at 20:39
  • @klanomath Thanks, did that (and edited .htaccess in post accordingly) but no difference unfortunately. Note that sudo apachectl -k restart says "httpd: illegal option -- k". Tried without -k, and also tried sudo apachectl stop and then sudo apachectl start separately. But still no difference.
    – RocketNuts
    Commented Apr 13, 2020 at 21:20
  • @klanomath But if I do sudo apachectl -v it says 2.4.43 i.e. the version I installed with brew (without sudo same result by the way). Is there a way to be sure? which apachectl tells me /usr/local/bin/apachectl.
    – RocketNuts
    Commented Apr 13, 2020 at 22:09
  • 1
    I ran a second test with htaccess_tester.php on GitHub which requires to brew install php, brew start php and add some lines to /usr/local/etc/httpd/httpd.conf and it works. If you send me your /usr/local/etc/httpd/httpd.conf I can do the annual service and compare it with mine. email: klanomath(at)googlemail.com
    – klanomath
    Commented Apr 13, 2020 at 22:10
  • 1
    I think it's the AllowOverride directive in your line 271 which should be All! Some other differences: I use $whoami/staff instead of _www/_www (which is rather unrelated)
    – klanomath
    Commented Apr 13, 2020 at 22:57

1 Answer 1

1

I changed the permission on line 271 from none to all and worked out

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .