Results 1 to 5 of 5

Thread: [RESOLVED] how do CMSs handle url rewriting with dynamic pages ?

  1. #1
    Join Date
    Aug 2007

    resolved [RESOLVED] how do CMSs handle url rewriting with dynamic pages ?


    this is probably quite a simple question for anyone with experience of CMSs like Joomla! and Drupal

    I currently use url rewriting in a couple of sites with the 'search engine friendly' urls and their dynamic equivalents hard-coded into the htaccess file.

    But how is this handled in the CMS world ?

    Is there a table in the DB containing the search-engine-friendly urls and their dynamic equivalents which is used to re-create the htaccess file each time a new page is created by the site admin ?

    Or is there a better way of doing it ?

    thanks for any pointers on this !

  2. #2
    Join Date
    Nov 2008
    I've never used the software you mention, but in CMS software I have written I tend to capture everything after the tld and parse it within a front controller type script. To give you a simple example of how you might use this, you may have a site which has urls like this:




    In your database of pages, you would have a field which contains the page's slug (the part of the url which uniquely identifies it - for example 'about-us' or 'how-to-write-php-code'). You then just query the database for the page matching the requested slug and display it.

    To handle this in your .htaccess you might do something like this:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond &#37;{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php?request=$1 [QSA,L]
    In your front controller script you can then access the request via $_GET['request'] as parse it as necessary. This is a very flexible approach since all of the routing takes place in your PHP script, so you can easily expand this to include other structures, categories for example.

  3. #3
    Join Date
    Aug 2007
    Thanks for your reply - it looks like a very interesting solution and I think it's exactly what i need for my mini-CMS

    I'm not exactly sure how the "RewriteCond %{REQUEST_FILENAME} !-d" works - but i'll read up on it !!

    thanks again

  4. #4
    Join Date
    Nov 2008
    The two RewriteCond lines just check if the request was for a directory or file (respectively) which actually exists. If you have an <img> tag for example, you don't want the HTTP request for the image to be redirected to your PHP script, you want to actually serve the image to the client. With both of those conditions in place, only requests for resources which do not actually exist on the server will be directed to your PHP script.

  5. #5
    Join Date
    Aug 2007
    Aha ! that's much clearer than the documentation I've been reading - thanks heaps !

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Recent Articles