Unique url for each directory using php and mod rewrite

Discussion in 'PHP' started by kshitijahuja, Sep 17, 2012.

  1. #1
    OK - sounds easy but here is detail.

    I would like to have several folders inside a main folder. Let's say an apps folder that will have several folders inside it which I want to be accessible using unique urls like

    example-Dot-com/apps/sdfsdfw435fdfsadf6af
    example-Dot-com/apps/dfasgklds9ef94brthg8

    This thing is that I do not really want to have directory names like that but just virtually. Like the first app above will be in folder "my-first-app" and the second will be in "my-second-app" and so on...

    Please share your thoughts and suggestions to implement this using php?


    Thanks
     
    kshitijahuja, Sep 17, 2012 IP
  2. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
    #2
    you mean something like this

    
    RewriteEngine on
    RewriteRule ^apps/sdfsdfw435fdfsadf6af/*$ apps/my-first-app/$1
    RewriteRule ^apps/dfasgklds9ef94brthg8/*$ apps/my-second-app/$1
    
    Code (markup):
     
    plussy, Sep 17, 2012 IP
  3. kshitijahuja

    kshitijahuja Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Somewhat. I just want the hashed/encrypted looking text to map on-to the real folders like my-first-app.

    The hashed/encrypted text value is to be generated dynamically from the database using some field values which I can use for mapping.
     
    kshitijahuja, Sep 17, 2012 IP
  4. babushkyn

    babushkyn Member

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    2
    Trophy Points:
    26
    #4
    I'd suggest rewriting urls to one file, and then inside decide what to do:

    RewriteEngine on
    RewriteRule ^apps/(a-z0-9)/*$ apps.php?hash=$1
    Code (markup):
    Otherwise you would have to generate .htaccess file every time you add new app to the database.
     
    babushkyn, Sep 17, 2012 IP
  5. kshitijahuja

    kshitijahuja Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yea, that looks more like it. But I have this query about "how"? I could write code to the app.php as you indicated above or even index.php in the app directory, but the question is how that hash is going to be linked back to the directory name which is in the form "my-first-app". This name is actually stored in the database or even the hash could be stored - I am ok with that.

    But the question is what should go inside the app.php file. I could get the hash and pull the data and match it from db and do some tricks to identity the real directory or in other words, map the hash to "my-first-app" in the php file but what next? Did you think I should "redirect" the url then to the actual directory name?

    Sorry, but I am not clear about "how" you suggested I should write the app.php file.

    Thanks
     
    kshitijahuja, Sep 17, 2012 IP