1

I'm looking for a while now how to enable .htaccess files in MAMP 2.1.2

I have the following settings:

httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so
...
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
# MAMP DOCUMENT_ROOT !! Don't remove this line !!
DocumentRoot "/Applications/MAMP/htdocs"

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories). 
#
# First, we configure the "default" to be a very restrictive set of 
# features.  
#
<Directory />
    Options Indexes FollowSymLinks
    AllowOverride All
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/Applications/MAMP/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options All

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

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory>
...
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride 
# directive.
#
AccessFileName .htaccess

The .htaccess file (Already working on the online website):

RewriteEngine on
RewriteRule ^([a-z\-]+)$ /index.php?page=$1 [L]

And the page output when i navigate to /foo

Not Found

The requested URL /index.php was not found on this server.

I tried adding the following line in the .htaccess file Because my site is on: localhost/mysite/ but didn't have any effect.

RewriteBase /mysite/

Accessing localhost/mysite/index.php?page=foo does work..

any Ideas?

3 Answers 3

1
+50

Here, you are using 2 features of apache :

  1. .htaccess files, which are managed by AllowOverride directives.
  2. rewrite_mod which is a module of Apache.

To enable .htaccess files management, you need to configure "AllowOverride" directive. Also, check that the AccessFileName is not modified (otherwise, you should rename your .htaccess file to the one configured in this directive.

To use url rewriting, the module rewrite_mod must be loaded.

As you are getting a 404 error, it points out that the AllowOverride direct is not correctly configured. After, if you are getting a 500 error, it means that the content of the .htaccess (so your rewrite configuration) has an error.

To have more details on the rewrite operations, you can also have a look on the RewriteLog directive.

Good luck !

2
  • I love your post, it has a create explanation. I will try some things with the AllowOverride again but as you can see in my config in my first post. All AllowOverride options are set to All.IF you have any more ideas regarding to my problem, i love to hear them.
    – Spons
    Nov 8, 2013 at 16:57
  • I reward you the points for the clear explanation on Error => Solution!
    – Spons
    Nov 8, 2013 at 17:08
0

In the end i found out that it was not the server configuration that was the problem. It was the .htaccess file that was the problem.

I changed:

RewriteEngine on
RewriteRule ^([a-z\-]+)$ /index.php?page=$1 [L]

To:

RewriteEngine on
RewriteRule ^([a-z\-]+)$ index.php?page=$1 [L]

And that did the job.

Thanks for the help guys.

1
  • /index.php was the issue for me as well. I just used index.php and it is fine
    – Linga
    Mar 10, 2021 at 10:04
0
vi /etc/hosts

Here you should see the localhost server name.

Then do:

vi /etc/apache2/sites-avaiable/000-default.conf

Instead of 000-default.conf, you can find something similar. Is your site configured here? You should see here something like:

<VirtualHost *:80>
ServerName localhost

    ServerAdmin webmaster@localhost
    DocumentRoot /Applications/MAMP/htdocs
            <Directory />
                            Order Deny,Allow
                            Deny from all
                            Options None
                            AllowOverride None
            </Directory>
            <Directory /Applications/MAMP/htdocs>
                            Options +FollowSymLinks +MultiViews
                            AllowOverride All
                            Order allow,deny
                            allow from all
                            Require all granted
            </Directory>

</VirtualHost>

You may have any AllowOverride none here.

Update:

I think I found the issue. When you do:

RewriteEngine on
RewriteRule ^([a-z\-]+)$ /index.php?page=$1 [L]

you are not allowing / in the regular expression. So try this:

RewriteEngine on
RewriteRule ^(mysite/)?([a-z\-]+)$ /$1index.php?page=$1 [L]

or

RewriteEngine on
RewriteRule ^([a-z\-]+)/([a-z\-]+)$ /$1/index.php?page=$2 [L]

Now, it should work for you in your localhost.

1
  • I love the explanation but i don't think that i wan't to go into that apache server. The apache server for me is configured in the /Applications/MAMP folder of my macbook. besides that the changes you provided are not changing anything in the situation, but thanks for the effort.
    – Spons
    Nov 8, 2013 at 16:54

You must log in to answer this question.

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