2

I'm trying to get mod rewrite to work on my Mac. This is the content of the .htaccess file:

<Files *\.ini>
  order allow,deny
  deny from all
</Files>

RewriteEngine on
RewriteRule .* index.php

I know this is active, because it's blocking .ini files properly, and it seems to rewrite the fictional request /foo to index.php, as this is the error I'm seeing in the browser:

The requested URL /Users/rwel/Sites/dev/quaestio/index.php was not found on this server.

The index.php file currently just contains an exit statement for testing purposes, and it does work when calling it directly. So, the question is, what's going wrong? I went into the apache error log, and this is what I saw:

[Thu Nov 03 14:36:02 2011] [error] [client 127.0.0.1] File does not exist: /Library/WebServer/Documents/Users

So the problem might be that it's not searching in the root, but relative to the /Library/WebServer/Documents directory. Am I right? How can I fix this?

Thanks for your help!

2 Answers 2

4

You should set up Virtual Hosts.

In /etc/apache2/httpd.conf uncomment the line:

#Include /private/etc/apache2/extra/httpd-vhosts.conf

Now edit /etc/apache2/extra/httpd-vhosts.conf. Remove the example vhosts, but do specify a default vhost as the first one. Here's an example config.

NameVirtualHost *:80

<VirtualHost *:80>
        DocumentRoot /Library/WebServer/Documents
</VirtualHost>

<VirtualHost *:80>
        ServerName myproject
        DocumentRoot /Users/username/Sites/myproject
        <Directory /Users/username/Sites/myproject>
                Order Allow,Deny
                Allow from all
        </Directory>
</VirtualHost>

Restart apache by running apache2ctl restart.

You should add an entry to your /etc/hosts file so that your servername resolves:

127.0.0.1  myproject

Now, when accessing the http://myproject, your rewrite rules will be relative to the right document root.

3
  • Thank you very much. I think you're probably right. I have tried the virtual hosts config before -- but I found that the downside was I couldn't access my /Library/WebServer/Documents folder anymore (this is where phpMyAdmin is installed).
    – Rijk
    Nov 3, 2011 at 15:41
  • With this example config localhost would still be serving /Library/WebServer/Documents. The first vhost is always the default one.
    – Gerry
    Nov 3, 2011 at 15:42
  • You're right, this first virtual host entry solved that problem. Your solution totally works! Thanks again :)
    – Rijk
    Nov 3, 2011 at 15:47
0

On top of Gerry's solution, I added AllowOverride All which made rewriting possible in my case;

<VirtualHost *:80>
        DocumentRoot /Library/WebServer/Documents
</VirtualHost>

<VirtualHost *:80>
        ServerName myproject
        DocumentRoot /Users/username/Sites/myproject
        <Directory /Users/username/Sites/myproject>
                Order Allow,Deny
                Allow from all
                AllowOverride All
        </Directory>
</VirtualHost>

Source: http://forum.joomla.org/viewtopic.php?t=518192

You must log in to answer this question.

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