PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 3, 2022

[FIXED] Apache doesn't seem to be detecting my .htaccess file

 February 03, 2022     .htaccess, apache, mamp, php     No comments   

Issue

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@site.com
   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.


Solution

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@site.com
   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



Answered By - Julien B.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing