2

I'm running an Apache server on my computer through MAMP, and I can't seem to get it to read my .htaccess file. All of the solutions I've looked at have said to make sure that my AllowOverride is set to All in httpd.conf, which it is, but this doesn't seem to resolve my issue. I know that .htaccess isn't being read since I've written some nonsense at the start of the file and no error is being produced. I have also restarted the Apache servers after changing httpd.conf. Maybe the problem is that I'm not completely sure where I'm supposed to place the .htaccess file.

My MAMP document root was formerly MAMP > htdocs, but I changed it to Library > WebServer > Documents, which is where all of my PHP files are located. The current project I'm working on is a subdirectory of this, say Library > WebServer > Documents > project. This is the folder that contains my .htaccess file. My httpd.conf file is in MAMP > conf > apache, and the relevant section of it is as follows:

# First, we configure the "default" to be a very restrictive set of 
# features.  
#
<Directory />
    Options Indexes FollowSymLinks
    AllowOverride All
</Directory>

Do I need to change the directory from / to something else to get this working? Any help is really appreciated.

Edit: I added the following <VirtualHost> block to my httpd.conf following the comments below, but again, nothing seems to change:

<VirtualHost *:80>
   ServerAdmin [email protected]
   ServerName localhost:8890

   DocumentRoot /
   <Directory />
      Options FollowSymLinks
      AllowOverride None
   </Directory>
   <Directory />
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all
   </Directory>
</VirtualHost>

Update (Solved): I was able to resolve the issue by reverting MAMP's DocumentRoot to its original MAMP > htdocs as opposed to my Library > WebServer > Documents. Apache is now reading the .htaccess file located in my MAMP > htdocs > project. Thanks everyone for the help.

11
  • 1
    This may or may not be relevant, but do you know the encoding of your .htaccess file? In my experience, Apache doesn't like a UTF-8 encoded .htaccess. So, for these files only, I use Windows 1252 instead.
    – Rounin
    Dec 23, 2020 at 0:33
  • 1
    Thanks for your reply, actually, I have no idea about its encoding. How can I check this and change it to the correct one?
    – Alec
    Dec 23, 2020 at 0:35
  • In Sublime Text, there is an option: Save with Encoding. You may select whichever you want, after which the file will then be saved with that encoding. I'm guessing other text editors will have similar options.
    – Rounin
    Dec 23, 2020 at 0:40
  • 1
    Oh I see, and which encoding do you recommend that I switch to? I have a list starting with some UTF's and followed by encodings corresponding to different languages. I don't see Windows 1252 on my list.
    – Alec
    Dec 23, 2020 at 0:45
  • 1
    I see, unfortunately it doesn't seem to change anything, but thanks regardless for the help.
    – Alec
    Dec 23, 2020 at 20:00

3 Answers 3

3
+50

First I would try to fix my VirtualHost to use the correct paths. I'm not super familiar with Mac, but if Library > WebServer > Documents > project corresponds to /Library/WebServer/Documents/project in your file system, then I would use that. Might be /home/your_username/Library/WebServer/Documents/project but as I said, I'm not a Mac guy. Next, I don't understand why you have directives for the same directory with opposite permissions, so I would try to remove the first Directory block or change the targetted directory to something else on one of the blocks. Note that you should never grant access to / with apache as it would be a very big security breach.

<VirtualHost *:80>
   ServerAdmin [email protected]
   ServerName localhost:8890

   DocumentRoot /Library/WebServer/Documents/project
   <Directory />
      AllowOverride none
      Require all denied
   </Directory>
   <Directory /Library/WebServer/Documents/project>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Require all granted
   </Directory>
</VirtualHost>

If it still doesn't work, you might want to make sure that the filename Apache is looking for hasn't been changed to something else using the AccessFileName directive.

Also, you are not giving details on where you put the VirtualHost block, but if it is in a separate file. Make sure you are including that file somehow.

You don't specify your Apache version but since version 2.4, you should Require instead of Allow directives since this is deprecated. See https://httpd.apache.org/docs/2.4/en/howto/access.html

1
  • Thanks for your answer, I tried updating the <VirtualHost> tag according to what you have above, but I still don't see any difference. The AccessFileName is still .htaccess. I think the issue is that the rules in the <Directory /Library/WebServer/Documents/project> tag aren't actually being applied to my project. Is there a way to check if they are? E.g. is there a command that would produce an error if I try to open project/index.php? I'm ok with typing the rules directly into my httpd.conf instead of a .htaccess file; all I need are some simple Rewrite commands for routing.
    – Alec
    Dec 27, 2020 at 0:37
3

Try adding Listen 80 and Listen 443 to the top of the main config.

3
  • Thanks for your answer. When I add Listen 80, I get an "Apache couldn't be started" error. I am able to add Listen 443, but this doesn't change anything unfortunately.
    – Alec
    Dec 26, 2020 at 20:23
  • When it failed to start, any further details in the logs?
    – kmuenkel
    Dec 26, 2020 at 20:36
  • I just tried it again with Listen 80 included but I only seem to get a message in the logs when I shut down the server, not when I start it up again.
    – Alec
    Dec 26, 2020 at 20:40
3

Check your httpd.conf. Via the AllowOverride (http://httpd.apache.org/docs/current/mod/core.html#allowoverride) and AllowOverrideList (http://httpd.apache.org/docs/current/mod/core.html#allowoverridelist) directives it can control whether or not .htaccess files are considered.

When this directive (i.e. AllowOverride) is set to None and AllowOverrideList is set to None, .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem.

Please note that the default value is None for both, which cause exactly this behavior of not considering .htaccess files.

1
  • Thanks for your reply, however all of my AllowOverride's are set to All in my httpd.conf file; I have no occurrences of AllowOverrideList.
    – Alec
    Dec 27, 2020 at 0:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.