1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development .htaccess/get-var leetness

Discussion in 'Software' started by Bruno_me, 2 Feb 2005.

  1. Bruno_me

    Bruno_me Fake-ad‎min

    Joined:
    30 Mar 2003
    Posts:
    1,136
    Likes Received:
    1
    right now, my site, bruno-me.org, is pretty much the way I want it, except I want it to do something like bash.org (like http://bash.org/?number or http://bash.org/?latest) or something like http://bruno-me.org/index.php/something

    it was kind of vague, but anyone know how to do something like this? my site is php on apache, so I can do get-vars and .htaccess

    edit: I already have ?item=something, so I don't need to do that
     
    Last edited: 2 Feb 2005
  2. eek

    eek CAMRA ***.

    Joined:
    23 Jan 2002
    Posts:
    1,600
    Likes Received:
    14
    mod_rewrite (an apache module) is all you need :)
     
  3. Bruno_me

    Bruno_me Fake-ad‎min

    Joined:
    30 Mar 2003
    Posts:
    1,136
    Likes Received:
    1
    what kind of rule do I need to add to do this?
     
  4. Bruno_me

    Bruno_me Fake-ad‎min

    Joined:
    30 Mar 2003
    Posts:
    1,136
    Likes Received:
    1
    I got this working, though not as I originally wanted, but it still is really cool... it now works like http://bruno-me.org/28 (article about it :p)
     
  5. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    You can do this without htaccess easily. I'm not saying that you should or shouldn't be doing this with htaccess, just providing you with the PHP alternative :D

    Firstly, for things like ?latest, you don't need the variable to actually hold a value to be able to use it - to state the obvious. As such, you could use index.php?latest to trigger something like so:

    Code:
    if(isset($_GET['latest']) && $_GET['latest'] == '') {
        #code to do something here
    }
    --

    As for index.php/blog/18, again easily done. If you accessed that URI, using $_SERVER['REQUEST_URI'], you would find it would be a string with the value:

    Code:
    /index.php/blog/18
    You can then manipulate the string.

    Code:
    $uri_array = explode(chr('47'), $_SERVER['REQUEST_URI']);
    /* $uri_array[0] = null
     * $uri_array[1] = index.php
     * $uri_array[2] = blog
     * $uri_array[3] = 18
     */
    Then based upon what is present in the array decide what you want to render on your page. I.e., you could use $uri_array[3] as a content ID and base a MySQL query on it.
     
  6. DeathAwaitsU

    DeathAwaitsU I'm Back :D

    Joined:
    27 Feb 2004
    Posts:
    2,104
    Likes Received:
    19
    Heyyyy, whats your problem with IE users :waah: .

    Death
     

Share This Page