How to correctly activate mod_rewrite mamp?

The local wordpress website home page runs well but mod_rewrite does not work. So, the home page works, but as soon as I click any link I get Not Found.

Log output for this error:

Read More
[error] [client 127.0.0.1] File does not exist: /Applications/MAMP/htdocs/myweb/my-web-page-that-has-to-work, referer: http://myweb.dev/

As per my understanding, the error would mean that it looks for that specific page instead of using mod_rewrite in order tot get the page from database.

httpd.conf relevant content:

# Virtual hosts, uncommented include
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

...

# AllowOverride All is here
<Directory "/Applications/MAMP/htdocs">
Options All
AllowOverride All
Order allow,deny
Allow from all
XSendFilePath "/Applications/MAMP/htdocs"
</Directory>

httpd-vhosts.conf relevant content:

<VirtualHost *:80>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/myweb"
ServerName myweb.dev
ServerAlias www.myweb.dev
ErrorLog "/private/var/log/apache2/myweb-error_log"
CustomLog "/private/var/log/apache2/myweb-access_log" common
</VirtualHost>

Any clue on how to get it to work?

Related posts

2 comments

  1. First make sure Apache loads the module. See: How to enable mod_rewrite for Apache 2.2

    Then add this to an .htaccess file inside your folder

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
    </IfModule>
    

    or just add it to your httpd-vhosts.conf like this. CORRECTED:

    <VirtualHost *:80>
      DocumentRoot "/Applications/MAMP/htdocs/myweb"
      ServerName myweb.dev
      ServerAlias www.myweb.dev
      ErrorLog "/private/var/log/apache2/myweb-error_log"
      CustomLog "/private/var/log/apache2/myweb-access_log" common
    
    
      <Directory "/Applications/MAMP/htdocs/myweb">
            AllowOverride All
            Allow from all  
    
            <IfModule mod_rewrite.c>
               RewriteEngine On
               RewriteBase /
            </IfModule>
    
      </Directory>
    
    </VirtualHost>
    

    Now add your rewrite rules for WP and see if it works.

    You may check if Apache is loading the module with a PHP script inside your folder. Try this and proceed from there.

    <?php
    
    if (in_array('mod_rewrite', apache_get_modules())) {
        echo "Yes, Apache supports mod_rewrite.";
    }
    
    else {
        echo "Apache is not loading mod_rewrite.";
    }
    
    1. First make sure MAMP Apache loads the module. MAMP has activated this by default.
    2. I made this for Joomla. WordPress should be similar. Mac would not allow you to rename the htaccess.txt in the root (htdocs/yourwebsite/)
    3. Instead of playing with Addons that show hidden files – the easiest way is to open Filezilla and rename the local file there. You use the usual wordpress htaccess and rename it to .htaccess
    4. Activeate rewrite as usual in the wordpress-backend.

Comments are closed.