SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Guru
    Join Date
    Feb 2008
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do you handle multiple variables and friendly URLs

    I was just wondering how people go about handling multiple variables and friendly URLs at the same time.

    Say for exmple I have this URL:

    http://example.com/index.php?act=view-cat&cat=christmas

    I can access it using the friendly URL:

    http://example.com/view-cat/christmas/

    But what about when I have this URL:

    http://example.com/index.php?act=vie...=50&offset=200

    But then what about when about when I miss some variables out and want to use the script defaults? For example:

    http://example.com/index.php?act=vie...mas&offset=200

    Can anybody give me some ides on how to handle this sort of situation?

    Thanks

  2. #2
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From the first 2 urls you have displayed it looks like you're lucky enough to have everything organised by directory. In that case you've pretty much solved your own problem until you've got other complex parameters which would probably break your program trying to have a directory structure which would no doubt include multiple copies of files etc.

    Ever thought of using short urls? - You could store parameters in a session or database and allow the user just to click a far shortened link to a page which can then automatically read the values from your storage location.

  3. #3
    SitePoint Zealot Kayarc's Avatar
    Join Date
    Sep 2009
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://example.com/category/christmas/

    depending on your situation you can pass the rest of the parameters an alternative way. What would people's thoughts be on session data with a one-page lifespan?
    Phoenix Arizona Web Design | info *at* kayarc.com | 602.633.2676

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you are concerned with duplicate contents also....google webmaster tool provides now option which url you want to exclude and which is the main url to index
    http://googlewebmastercentral.blogsp...canonical.html

  5. #5
    SitePoint Guru
    Join Date
    Feb 2008
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by seopeter View Post
    I think you are concerned with duplicate contents also....google webmaster tool provides now option which url you want to exclude and which is the main url to index
    http://googlewebmastercentral.blogsp...canonical.html
    I am somewhat concerned with duplicate content but this is software that I am distributing and I really don't think the canonical tag is appropriate for this problem.

    What happens is that you access a URL like this:

    http://example.com/view-cat/christmas/

    and you are given a listing with the default number of items per page, default offset of 0, default sort order and default sort direction.

    But what if people want to change the page offset? At the minute they have to use this URL:

    http://example.com/index.php?act=vie...tmas&offset=20

    And the script knows to use the default number of items per page and default sort order.

    I can't use the canonical tag here because it is a different page. It will contain a listing of different items.

    I need to be able to use friendly URLs for modifying page parameters.

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2008
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by me using - instead of / is better.
    I have a url php class that handles url prepare before submir request and url extract parameters on request and this way i have organized the things in one place

  7. #7
    SitePoint Guru
    Join Date
    Feb 2008
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kuzmanin View Post
    by me using - instead of / is better.
    I have a url php class that handles url prepare before submir request and url extract parameters on request and this way i have organized the things in one place
    I don't mind using - instead of /.

    Is this code that you can share?

  8. #8
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by corbyboy View Post
    But what if people want to change the page offset? At the minute they have to use this URL:

    http://example.com/index.php?act=vie...tmas&offset=20

    And the script knows to use the default number of items per page and default sort order.
    So why not store the parameters in a session? That way the url doesn't need all these other parameters in it and your scripts can still access the settings.

  9. #9
    SitePoint Guru
    Join Date
    Feb 2008
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tangoforce View Post
    So why not store the parameters in a session? That way the url doesn't need all these other parameters in it and your scripts can still access the settings.
    Because I still need to be able to link to the page. I need to be able to use page numbers which increase the offset on each page.

    For example if you have 10 items per page:

    http://example.com/index.php?act=vie...stmas&offset=0

    is page 1, and

    http://example.com/index.php?act=vie...tmas&offset=11

    is page 2.

  10. #10
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In that case I can't really see a practical way you can do it other than to use default values each time the script is called. It's simply not possible because somehow you MUST transmit those variables to the server. You either do it by GET or POST. You've ruled out GET and POST isn't really practical either. The only other thing to do is setup a database of dynamically generated short urls which when called you lookup in the database and read the variables from there. Each time a user visits the page you could put this friendly url in the page for them to copy and use.

  11. #11
    SitePoint Guru
    Join Date
    Feb 2008
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have not ruled out using GET at all, I just need a way to use friendly URLs in a consistent and reliable manner.

    For example, this would be the sort of thing I want:

    http://example.com/view-cat/christma...direction-asc/

    But I also need it so this works too:

    http://example.com/view-cat/christma...direction-asc/

    I guess this is more of a .htaccess question than a PHP one.

  12. #12
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    The first example seems like you would work well for your purposes. The only thing you would need to do is parse the server path info into an array. This could be a job for PHP or .htacess. I find it better to work clean urls into the application code rather then relying on some crazy rewrite. If you have PHP take care of all that is left is to rewrite everything to the index or entry point.

    I use a similar system. However, it doesn't support moving things around.

    1 - per-page
    2 - direction

    Then those would be mapped to the path info. So the arguments are referenced by name not placement in my code.

    $this->path->getOption('per-page');

  13. #13
    SitePoint Zealot Kayarc's Avatar
    Join Date
    Sep 2009
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what about something like

    PHP Code:
    <?php
    set_sessiondata
    ('per_page''20');
    ?>
    assuming set_sessiondata($name, $value)

    I assume that's how google works when you set the preferences
    Phoenix Arizona Web Design | info *at* kayarc.com | 602.633.2676

  14. #14
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I personally prefer using the query string for pagination. However, to cut down on the cruft in the URL, I only put the variables in the URL that are required. For example, if the default direction is ASC, and ASC is requested, then I won't put the direction in the URL on the next page/etc. links because it is very redundant. At minimum I just put the page or offset.

  15. #15
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Might I suggest looking into one of the mvc packages for php? You'd be able to write routes that are very flexible:

    For example, both of the urls below might be mapped to the following controller function:

    /category/<topic>/<offset>

    /category/christmas
    /category/christmas/11

    CategoryController::Index($topic, $offest = 0)

    Much cleaner.


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
  •