Grow your CSS skills. Land your dream job.

htaccess rewrite

  • # February 4, 2011 at 8:12 pm

    Hey guys. I’m working on a site for myself that acts similar to wordpress.

    I have this file- posts.php, so to see each post the correct url will be: /posts/post-name (I use the following rewrite):
    RewriteRule ^post/([^/]+).php /post.php?$1 [NC]

    I also use a rewrite that allows me to leave out the .php extension.

    And this works fine.. But I wanted to make it more specific for each post i.e., /rant/post-name without making a rant.php file to do so. So i wrote this in my htaccess file:
    RewriteRule ^rant/([^/]+).php /post.php?$1 [NC]

    I get a 404, and the server doesn’t point towards the post.php file and it tries to load /rant/post-name (which doesnt actually exist) yet, the first code still works no problem…

    what am I doing wrong?

    # February 4, 2011 at 8:15 pm

    Wow. I’ve been working on trying to fix this for the past 45 mins, and right after I posted this, I refreshed my page and everything was just fine..

    with that problem put aside, is there a better way of doing this?

    # February 6, 2011 at 1:32 am

    This may not be related, but I’ve seen all kinds of things happen depending on what host you are on. For instance, Godaddy doesn’t seem to support htaccess at all (or so I’ve heard and somewhat experienced). I’m probably not being much help but just my 2 cents :)

    gno
    # February 6, 2011 at 5:32 pm

    For .htaccess to work you need to be on a virtual host on an apache webserver with the AllowOverride configuration not set to None. :-)

    That is why it depends on hosts. .htaccess is not that weird ;-)

    # February 7, 2011 at 3:18 am

    well, i figured out what it was…

    Using this code, I was telling my server to look for rant.php
    ^rant/([^/]+).php /post.php?$1 [NC]

    this is the right code to use if rant.php does not exist.
    ^rant/([^/]+) /post.php?$1 [NC]

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".