Dynamically Custom URL Rewritting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neovantage
    New Member
    • Aug 2008
    • 245

    Dynamically Custom URL Rewritting

    I have developed a website for open source plugins. I want to do the URL rewriting. But as i am new in this so i need expert help in this regard.
    This is my website URL

    Header Menu is drawing dynamically. I mean it's a database oriented. Now i want if some one click on jQuery Link, My URL become

    Code:
    http://www.themosaicdesigns.com/jquery/
    instead of
    Code:
    http://www.themosaicdesigns.com/index.php?id=1
    if my website is static then i can do it using .htaccess but i don't know what id is coming when some one click on the link in header menu. Even i want if some click on sub link of jquery means first select jquery and then click on "Accordions | Menu | Form" it the URL must look like


    Code:
    http://www.themosaicdesigns.com/jquery/accordions-menu-form/
    instead of
    Code:
    http://www.themosaicdesigns.com/index.php?id=5
    Kindly help me out to sort out this issue i will be very grateful to him/her and it's really appriciated.

    Thanks in Advance,
    Mohsin Rafique
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    There is functionality within mod_rewrite for performing lookups with RewriteMap, however I'm not sure how efficient this is.

    Another way of approaching this task is to have an alias for each id in your database table (assuming you're using a database).

    Table:
    Code:
    |==============|
    | id |   alias |
    |==============|
    |  1 |  jquery |
    |  2 |     php |
    |  3 | c-sharp |
    |==============|
    Example code (PHP & MySQL):
    [code=php]
    <?php

    // Example URL request: http://yoursite/?alias=jquery
    // ...
    // Connect to your database
    // ...

    if (isset($_GET['alias'])) {
    $alias = $_GET['alias'];
    // Remember to sanitize your data!
    // Then use this alias as a lookup in your database table
    $sql = "SELECT * FROM `categories` WHERE `alias` = '$alias' LIMIT 1";
    // Etc.
    }
    [/code]

    Then you just have to rewrite the URL from http://yoursite?alias=jquery to http://yoursite/jquery

    Comment

    • neovantage
      New Member
      • Aug 2008
      • 245

      #3
      First of all thanks Markus for response.

      Your solution meets my query but there is a problem in this case and that is.

      If we have 2 processors of different comopanies Intel and AMD.
      Your given solution works in scenerio
      Code:
      http://www.themosaicdesigns.com/intel/processor/
      and
      Code:
      http://www.themosaicdesigns.com/amd/processor/
      but 404 error will come if some one write
      Code:
      http://www.themosaicdesigns.com/processor/
      What will we do in this case...?

      One solution which i have if no page found then it takes to a page where all the categories are list down.

      Is there any other possible solution for this...?

      Comment

      Working...