SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Dynamic Links?

  1. #1
    SitePoint Zealot Chameleon's Avatar
    Join Date
    Oct 2004
    Location
    Arizona
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Dynamic Links?

    I'm currently doing a whole new redesign of my website. I would like for it to be as much database driven as possible. One thing I would like instead of having the url like www.yoursite.com/articles.php I would rather it just show as www.yoursite.com/articles/
    the same for each navigation menu item. Im not even sure where to start to get this???

    Also how would I setup diffrent pages for diffrent categories, for example, in the store page have the url show as www.yoursite.com/store/ and then depending on the category you click have it show as www.yoursite.com/store/t-shirts/

    I also see some site that have a link like: www.yoursite.com/?p=tutorial&i=24

    If anyone can give me any infomation about how to do this or things I can read up on about this subject it would be really helpful!!

    Thank you for your time and I'm really sorry if this question gets asked alot or if its a noob question. It just has me confused since I'm used to using static links.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    mod_rewrite, which is discussed extensively in the apache configuration forum here, allows you to decouple your URLs from the file system. Essentially you write rules that point requests to URLs to actual files, so you can create any URL scheme you want.

    Simple example, you'd put this in a .htaccess file:
    Code:
    RewriteEngine On
    RewriteRule articles/(.*) article.php?id=$1
    Then http://www.example.com/articles/32 would cause your server to execute the request as if it was http://www.example.com/article.php?id=32, so your article.php file gets the request.

  3. #3
    SitePoint Zealot Chameleon's Avatar
    Join Date
    Oct 2004
    Location
    Arizona
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks dan,

    Would I have to set that up for every page that I would want the url to be re-writen?

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No, the rules are regular expressions, you only need as many rules as distinct patterns of URLs will exist.

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,192
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    Depending on how large your site is you could create a function to transform your get vars into the appropriate path. Than use $_SERVER['PATH_INFO'] to reconstruct a custom "$_GET" array. Than you would need to replace any link with a call to that function to output the new url.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •