.htaccess rewrite not working on localhost (mac os x apache) -- FIXED

Go To StackoverFlow.com

2

I'm using the built-in Apache on my Mac OS X (Snow Leopard) to do local testing of my websites. Currently I'm trying to create clean URLs for my PHP website, but I just can't seem to get it working.

Here's my .htaccess:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^gallery/page/([A-Z0-9._%+-]+) gallery/index.php?page=$1 [NC]

I'd like to have it so that http://localhost/gallery/page/TITLE will automatically bring me to http://localhost/gallery/index.php?page=TITLE

My http://localhost/ points to the local folder /Users/voltm/Sites/localhost/ and the website I'm working on is in http://localhost/gallery/ -- local folder /Users/voltm/Sites/localhost/gallery/

When I enter, for example, http://localhost/gallery/page/music in my browser, I get a 404 error The requested URL /gallery/page/music was not found on this server.

I looked into the error log file and it says:

[Thu Apr 05 23:55:39 2012] [error] [client 127.0.0.1] File does not exist: /Users/voltm/Sites/localhost/gallery/page

I've checked on phpinfo() and httpd.conf to see that mod_rewrite is loaded. I've gone into httpd.conf and the conf file in the user folder to make the settings:

Options Indexes MultiViews FollowSymLinks
AllowOverride All AuthConfig
Order allow,deny
Allow from all

And I've restarted Apache several times too.

What am I missing?


EDIT: Fixed! I had to remove the .htaccess file I had lying around in a subfolder.

2012-04-05 16:04
by Feanne


0

Finally figured it out! After hours of frustration - installed MAMP, fiddled with the conf files and looked at error logs - I finally came across the comment at the bottom of this page which said I shouldn't have .htaccess files "above and outside of MAMP's webroot directory". I had another .htaccess file in the gallery/ folder and I deleted it-- everything's working fine now.

2012-04-06 03:55
by Feanne
There are ways to configure the built-in Apache server in macOS to get it to do what you want. So, this isn't really an answer, but more of a workaround - Mike Ryan 2019-01-04 20:03
Ads