SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    rewrite rule not right,how to correct it

    when i close the rewrite. the url like the following:
    Code:
    http://example.com/about.php
    http://example.com/about.php?id=42
    http://example.com/products.php?id=43
    http://example.com/products_show.php?cid=49&id=46
    now i using the following code in .hactess file
    Code:
    RewriteEngine On
    RewriteBase /
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^index.html$ index.php
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^about-([0-9]+)-([0-9]+)\.html$ about.php?cid=$1&page=$2
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^product-([0-9]+)\.html$ product.php?cid=$1
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^productshow-([0-9]+)-([0-9]+)\.html$ productshow.php?cid=$1&id=$2
    Other pages are ok except product detail page and
    Code:
     http://example.com/about.php?id=42
    .what's wrong with the code? thank u.
    Outdoor tools online store and wargame tools shop
    with best quality and service.
    comp molle tactical vest tactical clothing etc sell

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Hello again, red!

    Personally, I won't use the RewriteBase / directive in the DocumentRoot - it's superfluous.

    Then, you're checking for the presence of a query string without remembering that (.*) is the EVERYTHING (or NOTHING) atom. In other words, you are deleting a pre-existing query string EVERY TIME (so why use the {REWRITE_COND} statements at all}?) and redirecting to a php script (NOT loopy).

    about.php?id=42 does not match any regex so it will survive and be processed by the PHP engine.

    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
  •