Solved

mod_rewrite help

Posted on 2004-10-26
186 Views
Last Modified: 2010-03-04
This seems pretty simple, but I cannot get it to work for the life of me...

I'm looking to turn these urls:  http://www.drunkdrinks.com/category.php?letter=a

into:  http://www.drunkdrinks.com/mixed_drink_recipes_letter/a

and http://www.drunkdrinks.com/category.php?pagenum=0&catid=8

into:  http://www.drunkdrinks.com/mixed_drink_recipes_category/0/8

Anyone know how to do this?  Thanks in advance!
0
Question by:jimday1982
    8 Comments
     

    Expert Comment

    by:radical_mit
    Hello,

    I would try and just the $_POST option within the <form> on the page before, these look like you are using $_GET

    so set you <form action="to the sub page" method="post">
    this should hide the ?letter=a for you .
    this might just help you with you problem.
    T
    0
     

    Author Comment

    by:jimday1982
    Not really sure what you're talking about here - I'm not trying to mess with my forms (yet, anyway), I'm just trying to make some of my links more SE friendly.  Thanks for your reply though.
    0
     
    LVL 2

    Expert Comment

    by:brozzis

    are you sure you want to solve this one with mod_rewrite ?

    place this code at the begin of the php file "mixed_drink_recipes_category"
    without extension. Remember to instruct your web server to use php to serve this file
    I placed this code in a file tokenizer.inc included whenever necessary,
    <?php
      if (strstr($PATH_INFO, "/")) {
       $p = substr($PATH_INFO, 1);
       $e_path = explode("/", $p);
       $i = 0;
       while ($i < count($e_path)) {
        $name = $e_path[$i];
        $val = $e_path[$i+1];
        $$name = $val;
        $i = $i+2;
       }
      }
    ?>

    in a file "myFile" without extension and then call it like this:

    http://myServer/myFile/param1/value1/param2/value2...

    it should be quite straightforward to modify this to accept a well defined order of parameters, like you want:

    http://www.drunkdrinks.com/mixed_drink_recipes_category/0/8

    bye...

    0
     
    LVL 5

    Expert Comment

    by:basiclife
    Ok, I don't know the answer because I'm after something similar myself but I just want to tell you you are going the right way about it - using mod_rewrite to convert "subdirectories" which don't exist into parameters for a PHP / other CGI script. Not sure why noone else is seeing it that way
    0
     
    LVL 5

    Expert Comment

    by:basiclife
    brozzis: The server would just return a 404 error without mod_rewrite wouldn't it?
    0
     
    LVL 2

    Accepted Solution

    by:

    no mod_rewrite is necessary, and still it works.
    I used the "tokenizer.inc" to hide parameters in GET calls, this is currently working.
    Server-side you must force on apache the use of php for every file requested,
    without checking for a .php extension, or use mod_rewrite to convert your calls
    FROM /mixed_drink_recipes_category TO /mixed_drink_recipes_category.php
    0
     
    LVL 5

    Expert Comment

    by:basiclife
    Hmmm. Nice workaround. I might haev to play with something like that. You learn something new every day. Thanks
    0
     
    LVL 2

    Expert Comment

    by:brozzis

    I gave a full and working solution...
    I think that basiclife should admit this...
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

     Java Android Coding Bundle

    Whether you're an Apple user or Android addict, learning to code for the Android platform is an extremely valuable, in-demand skill. It all starts with Java, the language behind the apps and games that make Android the top platform it is today.

    If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
    Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
    This video Micro Tutorial is the first in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles al…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    933 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now