Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I cannot get mod_rewrite to work on Lion. I am developing a number of websites locally, in ~/Sites, using .htaccess files. I am on 10.7.3 and I have not touched any configuration files except for enabling PHP in httpd.conf (which works).

I know there are at least 2 questions about this here, but the solutions detailed there don't work. Nor do the other solutions that I have found on the web. I must be doing something stupid or overlooking something, or else I am probably going crazy, but it's not working.

I've tried all the usual stuff:

  1. In /private/etc/apache2/users/<myusername>.conf, change AllowOverride None to AllowOverride All and restart the web server

  2. Additionally, in /private/etc/apache2/httpd.conf, change any/all occurrence(s) of AllowOverride None to AllowOverride All -- I've tried it in all the various places where these directives are found

  3. Try basically all possible combinations of values for the Options line above/below the AllowOverride line, including the values: Indexes MultiViews FollowSymLinks All

Always restarting the web server after such a change, of course. None of this works. All my clean urls simply do not work; I get a 404 - not found. Apache's error log just gives me "File does not exist:" errors. So it seems that the mod_rewrite module is not even working at all.

I made sure that mod_rewrite is loaded in the httpd.conf, which it is; it is so by default on a Lion install.

The crazy thing is that everything had been working perfectly -- until I migrated to a new machine running Lion. That is, I am ruling out an error in my .htaccess files because I know it worked before. Also, if it was an error in the .htaccess, I would get some kind of error message from the mod_rewrite module in Apache's error_log, at least telling me that the module itself is being called. But this is not happening.

Am I overlooking something? Do I have to change config settings someplace else? Do I have to change PHP's config? Why are the instructions (like How to activate mod_rewrite on MacOSX Lion and getting mod_rewrite to work on Mac OS X) working for other people but not for me? :)

I've wasted hours on this already. Any help would be VERY appreciated.

share|improve this question
    
BTW, I don't want to use MAMP. I used MAMP before and it didn't play well with the MySQL that is already on my system. This would be replacing one headache with another headache, so no thanks :) –  Niels Heidenreich Apr 3 '12 at 20:11
    
BTW I am on standard OS X Lion, NOT Lion Server. –  Niels Heidenreich Apr 3 '12 at 20:12
    
This doesn't answer the question, but an alternative to wrestling with your Mac's local environment for doing web dev is to use something like Vagrant, which lets you easily set up and manage virtual-machine configurations. –  Dan J Aug 20 '13 at 17:10

4 Answers 4

You should make sure that in your /etc/apache2/users/username.conf you have the following:

<Directory "/Users/username/Sites/">
    Options Indexes MultiViews FollowSymlinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

The FollowSymlinks and AllowOverride are essential here. While you are hinting at both in your question, maybe you did not configure these correctly in tandem.

Make sure in httpd.conf /private/etc/apache2/extra/httpd-userdir.conf is included as well. It is by default.

After any modifications, restart the web server for the changes to take effect.

If you are still having problems, maybe there is a problem with your actual rewrite rules. Were you using them in a .htaccess context before as well? Note that in a .htaccess, the rewrite rule regex is matched against a request URI without the leading slash and always relative to the directory where the .htaccess resides, whereas in a global httpd.conf the URI must match with a leading slash and is relative to the web root. Because assumedly you have your .htaccess in a subdirectory of ~/Sites, your rewrite rules might behave different from when the .htaccess resides in the web root of a (virtual) host.

To debug mod_rewrite you can enable rewrite logging. You should enable that in /etc/apache2/httpd.conf:

RewriteLogLevel 3
RewriteLog /path/to/rewrite.log
share|improve this answer
    
Thanks Gerry. Yes, I tried that; just tried it again; does not work unfortunately. I have not changed the .htaccess, it is in ~/Sites/…, as it was before. This is too frustrating :( –  Niels Heidenreich Apr 4 '12 at 19:24
    
Try enabling rewrite logging like I amended above. –  Gerry Apr 4 '12 at 19:50
    
OK, it's not a problem with mod_rewrite at all, as it seems; it's the .htaccess file that is completely ignored. I can place any junk into it and I get no error message. So Apache is not loading it. I checked permissions, they are ok (the file is world-readable). I tried making it executable, no change. –  Niels Heidenreich Apr 4 '12 at 20:29
    
If I place a .htaccess into /Library/WebServer/Documents and open "localhost/"; to test it, this works as expected. It just doesn't work in "~/Sites". –  Niels Heidenreich Apr 4 '12 at 20:30
    
I did something crazy and created a second user account with the login name "testitester". I set AllowOverride to All in that user's .conf. I placed a .htaccess containing junk in that user's Sites folder. If I go to localhost/~testitester, I get a 500 error, as expected. –  Niels Heidenreich Apr 4 '12 at 21:19

Adding Options +FollowSymLinks worked fine for me

Options +FollowSymLinks

RewriteEngine on
RewriteBase /
RewriteRule
share|improve this answer

Placing .htaccess into /Library/WebServer/Documents and open "localhost/"; to test it, works as expected. It just doesn't work in "~/Sites". Thanks Niels Heidenreich for this!

share|improve this answer

When you type: /Users/username/app_name

The / refers to the root of the webserver:

"localhost/"

If you use /~username/app_name in your rewrite it should work.

share|improve this answer
    
Paths starting with / are always absolute paths for Apache, see definition of webserver root in http.conf (<Directory "/Library/WebServer/Documents">) –  patrix Jan 31 '13 at 7:04

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.