Research the module "mod_rewrite" for apache and htaccess.. the answer is there : )

    mod_rewrite is a very powerful mod, sometimes too powerful... 🙂

    If you don't have access to Apache config and what not, another possiblity would be to do a little playing around with server vars.

    For example, this link:

    code.php/this/is/a/test

    Would return the following in the $_SERVER[ 'PATH_INFO' ] variable:

    /this/is/a/test

    So, if you know that the URL will always be in the same format, you could do something like:

    $forum = split('/', $_SERVER[ 'PATH_INFO' ]);
    

    With the above URL, that would give you an array like:

    Array
        (
            [1] => this
            [2] => is
            [3] => a
            [4] => test
        }
    

    Then you could use that array to pull the topic/etc.

    Hope that helps!

    -Percy

      Thanks majiclab.

      i understand whay you suggested but it implies that DB queries take place after the IDs are found out. That is not teh case.

      I have the IDs already and I want them converted to /3/4/5/.

      Any ideas?

      Thanks in advance

        In that case, just do something like this:

        <A hRef="http://domain.com/path/to/link.php/<?= $forum_id ?>/<?= $thread_id ?>/<?= $post_id ?>">Link</A>

        I think that's what you are trying to do... ?

        Hope that helps.

        -Percy

          Is there another way to do it? My server admin has switched off 'PATH_INFO' variable...

            does the server have mod_rewrite and is it *nix ?

              Thanks again majiclab for your suggestion. When I get the URL on screen like this <A hRef="http://domain.com/path/to/link.php/<?= $forum_id ?>/<?= $thread_id ?>/<?= $post_id ?>">Link</A> and the user clicks the link, of course I would need to fetch the forum_id, thread_d and post_id to get the article. One cannot do that as there are no variables to keep IDs in that URL formation you suggested. You see the problem?

              If the URL formation was <A hRef="http://domain.com/path/to/link.php?forum_id=$forum_id&thread_id= $thread_id&post_id= $post_id">Link</A> The problem of getting the article from database would have been easy because you have variables in the URL . But that is exactly what I am trying to avoid.

              You see my friend?

              Can I do this short of mod_rewrite implementation?

              Any more suggestions?

                Originally posted by rageh
                Thanks again majiclab for your suggestion. When I get the URL on screen like this <A hRef="http://domain.com/path/to/link.php/<?= $forum_id ?>/<?= $thread_id ?>/<?= $post_id ?>">Link</A> and the user clicks the link, of course I would need to fetch the forum_id, thread_d and post_id to get the article. One cannot do that as there are no variables to keep IDs in that URL formation you suggested. You see the problem?

                If the URL formation was <A hRef="http://domain.com/path/to/link.php?forum_id=$forum_id&thread_id= $thread_id&post_id= $post_id">Link</A> The problem of getting the article from database would have been easy because you have variables in the URL . But that is exactly what I am trying to avoid.

                You see my friend?

                Can I do this short of mod_rewrite implementation?

                Any more suggestions?

                If you'll read Tim's articles, you'll see how he used an apache attribute to force execution of one PHP script for the entire site, which deconstructs a query string similar to the first one you think impossible and creates the appropriate page for each request. That's one way it's done.

                  Write a Reply...