Dynamic URL's

Discussion in 'PHP' started by MrLeN, Mar 25, 2011.

  1. #1
    How can I make a dynamic folder structure, for folders that don't exist?

    ie, I want to make:

    www.mywebsite.com/billy
    www.mywebsite.com/sally
    www.mywebsite.com/bob
    etc (for a million other dynamic names)

    But I want every one of those urls to display the same content (that I will derive from an include).

    How can I do the above? I can't think of a way.
     
    MrLeN, Mar 25, 2011 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    I don't understand exactly what you're trying to accomplish. You would need a Rewrite Rule in an htaccess file (provided you're server is running Apache with mod_rewrite).

    That would have to be something like:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^([a-zA-Z])+$ test.php [L]
    Code (markup):
    You'd have to be careful if they all had the exact same content. You would need to specify either in a robots.txt file or meta robots tag that you don't want search engines to spider and index the pages, else you will be punished for duplicate content.
     
    Alex Roxon, Mar 25, 2011 IP
  3. jackburd

    jackburd Active Member

    Messages:
    396
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #3
    yes you can write htaccess or create folder.. or permalinks if your using wordpress
     
    jackburd, Mar 25, 2011 IP
  4. MrLeN

    MrLeN Well-Known Member

    Messages:
    406
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Ok, I will explain better:

    I have this include:

    /inc/username-info.php

    In that include, I will set variables for the username.

    Then, I will create a file:

    /inc/display.php

    This will use all the info that "username-info.php" contains.

    To get a page to know what username to use, I am not going to us:

    www.mywebsite.com/index.php?id=name

    I am going to use:

    www.mywebsite.com/username

    However, the folder "username" doesn't actually exist. It is dynamic.

    So, if someone goes to www.mywebsite.com/username, I want to display a page that conntains the paramaters I have set in the inc folder (for that username).

    How can I make a dynamic folder structure, for folders that don't exist?

    ie, I want to make:

    www.mywebsite.com/billy
    www.mywebsite.com/sally
    www.mywebsite.com/bob
    etc (for a million other dynamic names)

    But I want every one of those urls to display the same content (that I will derive from an include).

    How can I do the above? I can't think of a way.

    P.S. I don't want them to redirect. So I think I might have to use a url rewrite? ..and then have the particular information displayed, according to the username that was entered?
     
    MrLeN, Mar 25, 2011 IP