Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

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 !

share|improve this answer
    
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 '13 at 16:57
    
I reward you the points for the clear explanation on Error => Solution! –  spons Nov 8 '13 at 17:08
up vote 0 down vote accepted

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.

share|improve this answer
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.

share|improve this answer
    
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 '13 at 16:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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