Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: htaccess issue

  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Thanked 0 Times in 0 Posts

    Unhappy htaccess issue

    First off - HELP!

    I have looked high and low, up and down and still can't get this working. What I am trying to do it get a rewrite rule that handles up to 4 directories. Here is what I am looking for


    This redirects to index.php?city=$1&state=$2&cat=$3&subcat=$4

    But I won't always have 4, I want to be able to redirect to:

    or /city/state/cat/subcat/

    Here is my .htacess

    RewriteEngine on
    RewriteRule ^([A-Z,a-z,0-9,\_]*)/([A-Z,a-z,0-9,\_]*)/([A-Z,a-z,0-9,\_]*)/([A-Z,a-z,0-9,\_]*) /location.php?city=$1&state=$2&category=$3&subcat=$4

    It works so long as I have the right number of slashes

    For instance city/state/// works
    or city/state/cat/

    Is there some way to make this work without the slashes and be able the handle the 3 items above, or better yet, all four

    Thanks in advance

  • #2
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Thanked 15 Times in 15 Posts


    I'm not clued up on the .htaccess stuff, but this may help - url-rewriting

    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Thanked 2,232 Times in 2,219 Posts
    Quote Originally Posted by webmmt View Post
    For instance city/state/// works
    or city/state/cat/
    I'd use a different method, like
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?page=$1 [L]
    The above rule redirects everything in the requrest_uri to the index.php page (where 'page' is just a dummy variable).

    Then I use
    PHP Code:
    , which gives an array with all the items separated by / in the url. Thus I can interpret it as
    PHP Code:
    Based on this I'd write the conditions/includes to serve the corresponding pages (and a custom 404 page also, if required).
    Last edited by abduraooft; 12-20-2008 at 03:13 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts