aurel
aurel

Reputation: 3132

How to get MAMP to read .htaccess files

I am trying to get the .htaccess working in MAMP. The content of the .htaccess is a simple redirect line, but the entire .htaccess file seems to have no effect, even when I change it to contain invalid data.

Is there any settings within MAMP I need to change to enable .htaccess files?

Upvotes: 57

Views: 123349

Answers (8)

MUHINDO
MUHINDO

Reputation: 1213

just remove the "#" from this line.

LoadModule rewrite_module modules/mod_rewrite.so

In httpd.conf in /Applications/MAMP/conf/apache

Upvotes: 0

Goulven
Goulven

Reputation: 889

I've just downloaded MAMP and had the same issue. The .htaccess file was being read (since Apache returns a 500 when adding AllowOverride All), but redirects were ignored because mod_rewrite was not loaded. It's easy to fix:

  1. Open /Applications/MAMP/conf/apache/httpd.conf, find the line containing #LoadModule rewrite_module modules/mod_rewrite.so (line 179 on my install) then remove the leading #.
  2. Reopen MAMP, click Stop then Start to restart Apache.

Most PHP projects use mod_rewrite these days, it should be enabled by default.

Upvotes: 1

Yarik
Yarik

Reputation: 742

I have MAMP v 6.6.2 (year 2022), and I was trying to make working php friendly URLs on my localhost Apache, by adding '.htaccess' file to my website root directory ("localhost/mywebsite/.htaccess"):

RewriteEngine On   
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]  

Which didn't work. But I tested it on cPanel hosting on a real domain and it worked fine.

So I have tried to change httpd.conf with these advises:

  1. https://stackoverflow.com/a/21411933/3936149 - didn't help
  2. https://stackoverflow.com/a/7670598/3936149 - didn't help
  3. https://stackoverflow.com/a/19204983/3936149 - didn't help

In the end I came up to an advise:

I simply commented out the second line of the code in my '.htaccess' (located at "localhost/mywebsite/.htaccess") file and that's it:

RewriteEngine On   
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]  

After it started to work I reverted all the changes in httpd.conf file, I have done above, and it was still working.

Upvotes: 0

Emanuil Rusev
Emanuil Rusev

Reputation: 35265

  1. In httpd.conf on /Applications/MAMP/conf/apache, find:

    <Directory />
        Options Indexes FollowSymLinks
        AllowOverride None
    </Directory>
    
  2. Replace None with All.

  3. Restart MAMP servers.

Upvotes: 107

salahy
salahy

Reputation: 1207

Go to httpd.conf on /Applications/MAMP/conf/apache and see if the LoadModule rewrite_module modules/mod_rewrite.so line is un-commented (without the # at the beginning)

and change these from ...

<VirtualHost *:80>
    ServerName ...
    DocumentRoot /....
</VirtualHost>

To this:

<VirtualHost *:80>
    ServerAdmin ...
    ServerName ...

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

Upvotes: 44

qommander
qommander

Reputation: 83

I'm using MAMP (downloaded today) and had this problem also. The issue is with this version of the MAMP stack's default httpd.conf directive around line 370. Look at httpd.conf down at around line 370 and you will find:

<Directory "/Applications/MAMP/bin/mamp">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

You need to change: AllowOverride None To: AllowOverride All

Upvotes: 8

SomethingOn
SomethingOn

Reputation: 10911

The problem I was having with the rewrite is that some .htaccess files for Codeigniter, etc come with

RewriteBase /

Which doesn't seem to work in MAMP...at least for me.

Upvotes: 5

strangerpixel
strangerpixel

Reputation: 828

If you have MAMP PRO you can set up a host like mysite.local, then add some options from the 'Advanced' panel in the main window. Just switch on the options 'Indexes' and 'MultiViews'. 'Includes' and 'FollowSymLinks' should already be checked.

Upvotes: 5

Related Questions