0
votes

I am trying to get .htaccess to work in my localhost (I've got Mac OS X 10.5). I enabled .htaccess by following articles like this one. But although now the rewriting is taking place, it is not working correctly. As an example, one of the rewrite rules is:

RewriteRule ^(home|faq|about|contact)$ index.php?section=$1 [QSA,NC]

So when I enter http://localhost/~MyUsername/MyWebsite/home, I should be shown http://localhost/~MyUsername/Mywebsite/index.php?section=home ...but instead, a 404 error occurs, and the error message is "The requested URL /Users/MyUsername/Sites/MyWebsite/index.php was not found on this server."

My guess is that something in my Apache configuration is wrong (the rewrite rule works fine in my online host), but how to solve it is beyond my knowledge. Any ideas? Thanks in advance.

1
Does /Users/MyUsername/Sites/MyWebsite/index.php exist?Rob
I had forgotten to include the "RewriteBase /" command. Now that I did, the 404 error message reads: "The requested URL /index.php was not found on this server."Sophivorus
This cannot be treated as an answer -- but install MAMP or similar package (or just properly configure what you have right now). The problem with URL rewriting that you are facing right now may be linked to the fact that you are using ~MyUsername/... kind of path. Ideally to access your homepage you should be just typing http://localhost/ (or very similar) and that's it (no /~MyUsername/MyWebsite/ part). This makes URL rewriting much more difficult (especially when user's home folder is involved).LazyOne
In short -- Apache may not have enough access rights to access website files in your home folder. Try moving website outside /Users/ folder.LazyOne

1 Answers

1
votes

Try the following RewriteRule:

RewriteRule ^/(.*)/(home|faq|about|contact)$ /$1/index.php?section=$2 [QSA,NC]

You can test your rewrite rules here - http://martinmelin.se/rewrite-rule-tester/