URL's that dont follow folder structure? How is it done?

Discussion in 'Programming' started by Lost&found, May 18, 2010.

  1. #1
    As you can tell by the title of my post I am very new to php and any other language for that matter.

    I am trying to find an online source that can explain why it is that some URL's work that dont follow a folder structure. For example in wordpress after changing the linking structure from default query URL's in to custom permalink structure (/%category%/%postname%/). How is this done? Is this an apache thing or a php thing?

    If anyone could shed some light on this for me that would be greatly appreciated.
     
    Lost&found, May 18, 2010 IP
  2. Fervid

    Fervid Well-Known Member

    Messages:
    161
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    120
    #2
    With WordPress it's both Apache and PHP. You can easily rewrite urls without php however. Google .htaccess rewrite for more info.
     
    Fervid, May 18, 2010 IP
  3. Lost&found

    Lost&found Guest

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    OK so I did some looking around and realized that apache can be very tough. If someone could direct me to an in depth source for a query mod rewrite or give a sample of the kind of code I should be learning to work with that would be a day maker for me.

    Thanks
     
    Lost&found, May 31, 2010 IP
  4. trevHCS

    trevHCS Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Your right it can be very complicated, but then a lot of it is simply the syntax which when you break it down becomes a lot lot more logical. It's because mod_rewrite allows regular expressions that it looks so bizare and if you have a basic understanding of them it does help.

    Never found a definitive source, but there's a few promising tutorials in this Google link to mod_rewrite tutorials

    The essence to remember is that there are 2 things you can do within a rewrite.

    1) RewriteCond is like a basic "If X = Y do Z" although annoyingly basic sometimes.
    2) RewriteRule which is the bit which says something on the left changes to something on the right.


    Example:

    Going by what you were asking about, this is a quick example since personally I rarely worry about RewriteCond.

    RewriteRule ^/my-fake-directory/$  /myscripts/printer.php?fakedir=1
    Code (markup):
    In this case the user would see www.example.com/my-fake-directory/ but the mod_rewrite catches that call and triggers the printer script under /myscripts/printer.php passing it the query string.

    It can seem to get complicated very quickly, but hopefully those tutorials will give you the basics and then you can just turn things around as you want.

    Trev
     
    trevHCS, Jun 1, 2010 IP
  5. windy

    windy Active Member

    Messages:
    1,093
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #5
    you can edit .htaccess file to redirect URLS
     
    windy, Jun 5, 2010 IP