SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot busylinks1's Avatar
    Join Date
    Nov 2008
    0 Post(s)
    0 Thread(s)

    Urgent: mod_rewrite problem

    Hi guys

    I am new to using mod_rewrite, but need it for a project I am currently working on.

    My problem is that I have one php file for searching that reacts differently with different number of parameters like category name, city name and state...
    Now problem is that system cannot differentiate different parameters and always take first parameter as category name even it is city or state name

    Simply saying I want to re-write URLs as.

    domain-name/search.php?catname=abc as domain-name/abc.html

    domain-name/search.php?catname=abc&city=efg as domain-name/abc-in-efg.html

    domain-name/search.php?catname=abc&city=efg&state=xyz as domain-name/abc-in-efg-in-wyz.html

    domain-name/search.php?city=efg as domain-name/efg.html

    domain-name/search.php?state=xyz as domain-name/xyz.html

    Please let me know if it is possible or I can adopt any better way to achieve this…

    Hope someone can help me?


  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    19 Post(s)
    3 Thread(s)

    Sorry, it's not possible BECAUSE Apache's mod_rewrite cannot differentiate between your abc.html, efg.html and xyz.html, i.e., is it a catname, city name or state name? Okay, if you have a limited list of catnames and (UGH) there is a limited list of state names so you COULD list them in your regex like (AL|AK|AR|...) but that's a terrible solution (IMHO). Of course, without more information about your search function, it's difficult to make a good suggestion.

    In my signature's tutorial, I used city, state and country in my example (to develop regex) and you may get something out of that that you can use.

    As for me, I'd suggest, and - or something like that so that you can differentiate your regex for these different mod_rewrite blocks.


    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


Posting Permissions

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