View Full Version : Help with htaccess inside MAMP
Bostonaholic
Dec 11, 2009, 09:54 PM
I'm trying to implement clean urls for my website. I'd like to use the mod_rewrite module to do this. I have created a .htaccess file to do so. When I upload the file to my hosted webserver, it works just fine but when testing locally with MAMP, it does not. I have searched all around the web and I can't find a solution.
Here's my configuration:
/Users/matthew/Sites/matthewboston/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/about/?$ ./about.php [QSA,L]
RewriteRule ^/entry/([0-9]+)/?$ /index.php?id=$1 [QSA,L]
</IfModule>
/Applications/MAMP/conf/apache/http.conf
...
LoadModule rewrite_module modules/mod_rewrite.so
...
<Directory "/Users/matthew/Sites/matthewboston">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
...
AccessFileName .htaccess
...
I think that's all the important info...
Help please!!
Bostonaholic
Dec 11, 2009, 10:01 PM
I don't know how much it matters but I just noticed something. In my htaccess file it is checking <IfModule mod_rewrite.c> but in http.conf it uses mod_rewrite.so
I removed the 'If' statement but that didn't fix the problem. Would this cause issues anyway?
angelwatt
Dec 12, 2009, 06:20 AM
Syntax-wise it looks alright. In my .htaccess I don't use the IfModule tags. You can try removing that tag (and end tag).
What type of results are you currently get?
Bostonaholic
Dec 12, 2009, 11:08 AM
Syntax-wise it looks alright. In my .htaccess I don't use the IfModule tags. You can try removing that tag (and end tag).
What type of results are you currently get?
I try to access http://localhost:8888/about/ and I get
404 Not Found
The requested URL /about/ was not found on this server.
Bostonaholic
Dec 12, 2009, 01:49 PM
Ok, so I know MAMP's apache is reading the .htaccess file cause I added
ErrorDocument 404 /404.php
and it correctly displays 404.php for missing pages. So it just seems to be the RewriteRule's that aren't working properly...
angelwatt
Dec 12, 2009, 03:16 PM
For the about line, that period is like causing problems so it can be removed.
RewriteRule ^/about/?$ /about.php [QSA,L]
Bostonaholic
Dec 12, 2009, 03:22 PM
For the about line, that period is like causing problems so it can be removed.
RewriteRule ^/about/?$ /about.php [QSA,L]
I thought that too. I changed it and it still didn't help.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^/about/?$ /about.php [QSA,L]
RewriteRule ^/entry/([0-9]+)\.php$ /index.php?id=$1 [QSA,L]
ErrorDocument 404 /404.php
angelwatt
Dec 12, 2009, 03:40 PM
Does the entry line work locally? You may want to try swapping the two lines (about and entry) to see if it has any effect. Also, when you try things in your browser locally, does it show what URL it's attempting to create, after the rewrite? Just trying to figure out if the rewrite line is simply not triggering when it should, or if they rewrite is not writing to the correct format. It's weird though that it works on your site.
One quick thing that just came to mind. When you edited the httpd.conf file, did you restart the web server? It needs to be restarted when editing that file. Editing the .htaccess file does not though.
Bostonaholic
Dec 12, 2009, 03:55 PM
Does the entry line work locally? You may want to try swapping the two lines (about and entry) to see if it has any effect. Also, when you try things in your browser locally, does it show what URL it's attempting to create, after the rewrite? Just trying to figure out if the rewrite line is simply not triggering when it should, or if they rewrite is not writing to the correct format. It's weird though that it works on your site.
One quick thing that just came to mind. When you edited the httpd.conf file, did you restart the web server? It needs to be restarted when editing that file. Editing the .htaccess file does not though.
Nope, the entry line doesn't work either. When the rewrite doesn't work I get a 404 and the url in the browser reads http://localhost:8888/about/.
I never edited the httpd.conf file, by default it had those settings. And these issues have existed after multiple restarts of the server.
I appreciate your help, angelwatt. You, SrWebDeveloper and savar are great!
Bostonaholic
Dec 12, 2009, 04:37 PM
Grrrrrrr, I finally figured it out.
I need to use this
RewriteRule ^about/?$ /about.php [QSA,L]
RewriteRule ^entry/([0-9]+)\.php$ /index.php?id=$1 [QSA,L]
It was the / in front of the about and entry in the regular expression. I was reading this page - http://corz.org/serv/tricks/htaccess2.php - and about halfway down it mentions
Remember, if you put these rules in the main server conf file (usually httpd.conf) rather than an .htaccess file, you'll need to use ^/... ... instead of ^... ... at the beginning of the RewriteRule line, in other words, add a slash.
So then I took out the first slash and now it works. I still don't know why it worked on my hosted site (GoDaddy) and not locally using MAMP. Oh well. Thanks angelwatt!
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.