SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    619
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    select box - page not found error htaccess

    hi all

    i have this is my htaccess

    Code:
    RewriteRule ^items-([0-9]+)-([0-9]+)-([^/\.]+)-([^/\.]+)$  items.php?dler_id=$1&ctgry_id=$2&page=$3&choice=$4
    url i get is
    Code:
    http://localhost/foldername/items-8-1-1-high
    When i paste the above url address in the addressbar then the page is displayed absolutely fine.

    but when i choose option from the select box and click submit then i get
    Code:
    "page not found" error
    this is my select box code
    Code:
    <? 
    $choice = $_REQUEST['choice'];
    $urlg = "http://localhost/foldername/items-".$dler_id."-".$ctgry_id."-1-"."$choice"; 
    /* output = http://localhost/foldername/items-8-1-1-high */
    ?>
    
    <form id="sortform" name="sortform" action="<? echo $urlg ?>" method="post">
    <select class="sortselect" name="choice" id="choice">
    <option value="high">Price high to low</option>
    <option value="low">Price low to high</option>
    </select>
    <input name="submit" id="submit" type="submit" value="" />
    </form>
    vineet

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    vineet,

    I'll not worry that you have no text in your submit button but go straight to the mod_rewrite code.

    Code:
    RewriteRule ^items-([0-9]+)-([0-9]+)-([^/\.]+)-([^/\.]+)$  items.php?dler_id=$1&ctgry_id=$2&page=$3&choice=$4
    First, kudos to you for understanding enough to NOT use the dreaded (.*) to match garbage.

    Second, no Last flag?

    Third, you do not need to (therefore, you should not) escape the dot character within a character range definition.

    Lastly, on the assumption that you only use the .htaccess in the DocumentRoot (here, that's localhost), your leading start anchor is ignoring the folder in your URI and is, therefore, failing to match your URI and performing the redirection.

    Only the last "error" (failing to account for the folder in your RewriteRule) will prevent your code from working. Hint: deleting the ^ will have the same effect as implementing this code for every subdirectory else add folder/ after the start anchor. If your .htaccess is within the folder directory, then you may need to add a leading / - I'd make that /? as subdirectories handle the leading / differently and I'm too tired to remember if it's required here or not.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    619
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hi dk

    All my webpages including .htaccess file are in same "folder".

    so it should match the url.

    But it didnt matched in my case.

    no files exists directly under localhost

    vineet

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    vineet,

    Okay, then the last paragraph above applies.

    Of course, I should mention that you can (SHOULD) create virtual hosts on your development machine as it's both simple and highly effective when testing your domains (locally). To do that, you'll need to edit the httpd.conf file to include the extras/httpd-vhosts.conf file, you'll need to add your localhost's domain with the path to your localhost domain (WARNING: Do NOT use the fully qualified domain name, e.g., for dk.co.nz I used dk), edit your windows\system32\drivers\etc\hosts file to include 127.0.0.1 domain and restart Apache.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    619
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hi dk

    one last question

    whats the drawback of not using Last flag [L]

    what happens if i dont use [L] Flag

    Is it mandatory to mention [L] to all my rewrite rules.

    If there are 10 rewrite rules then i have to mention [L] for all 10 rewrite rules.

    vineet

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    vineet,

    "I thought I was wrong once but I was mistaken."

    I used to believe that mod_rewrite ANDed successive RewriteRules ... but that is INCORRECT!

    The point of the Last flag is to direct mod_rewrite to begin its next pass through your code before going through the remainder of your mod_rewrite code.

    I still have the mindset that the Last flag is as necessary as the ; in PHP but, IF there is a reason to run other directives with the updated {REQUEST_URI} string before the next iteration (which will run that code anyway), by all means, do so. The timing advantage of restarting immediately is surely minimal.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

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