Question about a php urls

Discussion in 'PHP' started by philpbvc3232, Sep 2, 2010.

  1. #1
    How do you get URLs like below when using php?

    http://domain.com/photos/022010/01/

    Where it normally is written like this:

    http://domain.com/photos.php?date=022010&id=01

    I see sites like this all the time now and am curious how this is accomplished. I do have an idea though...

    When creating a directory for example photos. Do I just put an index.php file in that directory and just in my php instead of calling on a href as "?date=.$row['date']." do I call it as "/.$row['date']./" ?

    Hope that is explained well. I guess twitter would be an example of what I am talking about. I just cannot recall the url where I specifically saw this.

    If someone does know what I am talking about can they please shed some more light on it?
    Thanks!
     
    philpbvc3232, Sep 2, 2010 IP
  2. jpratama

    jpratama Member

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    Hi Phil, I can give you a clue. It doesn't relate with PHP. It has something to do with mod_rewrite and .htaccess. You can find this clean url method by googling.
     
    jpratama, Sep 2, 2010 IP
  3. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #3
    Rainulf, Sep 2, 2010 IP
  4. open-seo

    open-seo Peon

    Messages:
    115
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you need to edit .htaccess file if u use apache. see this
     
    open-seo, Sep 3, 2010 IP
  5. Rodingo

    Rodingo Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yeah.. use .htacess
     
    Rodingo, Sep 3, 2010 IP
  6. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #6
    Mod rewrite is a very easy to use Apache module which uses regular expressions to find matches and replaces them as a redirect.

    A basic one would be something like this,

    
    RewriteEngine On
    
    RewriteRule ^([^.]+).html /index.php?page=$1
    
    
    Code (markup):
    Say we had a index file which was loading the content via index.php?page=home, now we could have it look like home.html but it's really index.php?page=home It's not actually like that it's the beauty of mod rewrite, just from that example that will get you started.

    Kind regards,

    Glen Hughes
     
    HuggyEssex, Sep 3, 2010 IP
  7. puya4ever

    puya4ever Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes. Your answer is .htaccess . Be sure that your server have the mod_rewrite enabled to use .htaccess . Good Luck .
     
    puya4ever, Sep 3, 2010 IP