SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    EU - Slovakia
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to work with virtual (seo) URLs?

    Hi folks,
    my another question is how to work with URLs like below in PHP:

    http://www.example.com/section/
    http://www.example.com/section/subsection/
    http://www.example.com/section/subse...subsubsection/
    http://www.example.com/section/subse...subsubsection/ ....

    These URLs works very well with this mod_rewrite rules:

    Code:
    RewriteEngine On
    
    #check if file or directory real exists:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    #do the rule only if the address has no extension:
    RewriteCond %{REQUEST_URI} !\.[[:alnum:]]+$
    #replace /whatever to /whatever/, not apply to whatever/!
    RewriteRule ^(.+[^/])$ /$1/ [R]
    
    #do the rule only if the address ends with trailing slash:
    RewriteCond %{REQUEST_URI} ^.*/$
    #if the rule ends with trailing slash then redirect to index.php..
    RewriteRule ^(.*)/$ /index.php?p=$1 [L]
    So Apache stage is solved, but how about the PHP stage?
    The problem is that there can be many of subsections and how I can know that for example /animals/ is a subsection of /photogallery/ and not /profile/ ???

    http://www.example.com/photogallery/animals/ - GOOD
    http://www.example.com/profile/animals/ - BAD

    How do you solve these things?

    One idea which I had is to store sections in array an then compare them with the section's name in URL, but I can't get it work for more nested URL's.

    Any ideas or web resources are appreciated!
    Cheers.

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Location
    Atlantis
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is not something different than normal URL's. How were you handling it before rewrite like it was ?section=photogallery&sub=animals .

    Check against a database if $_GET['sub'] is included in $_GET['section'] in rows?

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    EU - Slovakia
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Aras
    This is not something different than normal URL's. How were you handling it before rewrite like it was ?section=photogallery&sub=animals .

    Check against a database if $_GET['sub'] is included in $_GET['section'] in rows?
    Hmm yes, but in my case I have everything only in just $p variable. But that is not problem I can parse it with explode().
    But what about if I exactly don't know how many subsections will be generated? I wanted an universal solution. If I limit the subsections then yes, I can do what you said.

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Location
    Atlantis
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I could not understand you clearly. Dont you read these subsections from database? What do you mean by limit?

  5. #5
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Saul

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    EU - Slovakia
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, I will read this, it looks great.


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
  •