Help with htaccess inside MAMP

Discussion in 'Web Design and Development' started by Bostonaholic, Dec 11, 2009.

  1. Bostonaholic macrumors 6502

    Bostonaholic

    Joined:
    Aug 21, 2009
    Location:
    Columbus, Ohio
    #1
    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
    Code:
    <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
    Code:
    ...
    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!!
     
  2. Bostonaholic thread starter macrumors 6502

    Bostonaholic

    Joined:
    Aug 21, 2009
    Location:
    Columbus, Ohio
    #2
    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?
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    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?
     
  4. Bostonaholic thread starter macrumors 6502

    Bostonaholic

    Joined:
    Aug 21, 2009
    Location:
    Columbus, Ohio
    #4
    I try to access http://localhost:8888/about/ and I get

    404 Not Found

    The requested URL /about/ was not found on this server.
     
  5. Bostonaholic thread starter macrumors 6502

    Bostonaholic

    Joined:
    Aug 21, 2009
    Location:
    Columbus, Ohio
    #5
    Ok, so I know MAMP's apache is reading the .htaccess file cause I added
    Code:
    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...
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    For the about line, that period is like causing problems so it can be removed.
    Code:
    RewriteRule ^/about/?$ /about.php [QSA,L]
     
  7. Bostonaholic thread starter macrumors 6502

    Bostonaholic

    Joined:
    Aug 21, 2009
    Location:
    Columbus, Ohio
    #7
    I thought that too. I changed it and it still didn't help.
    Code:
    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
     
  8. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #8
    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.
     
  9. Bostonaholic thread starter macrumors 6502

    Bostonaholic

    Joined:
    Aug 21, 2009
    Location:
    Columbus, Ohio
    #9
    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!
     
  10. Bostonaholic thread starter macrumors 6502

    Bostonaholic

    Joined:
    Aug 21, 2009
    Location:
    Columbus, Ohio
    #10
    Grrrrrrr, I finally figured it out.

    I need to use this
    Code:
    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
    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!
     

Share This Page