Results 1 to 1 of 1

Thread: Making Friendly URLs

  1. #1
    Former lead dev Nick's Avatar
    Join Date
    Jun 2009
    Location
    Kakamigahara, Japan
    Posts
    2,859
    Blog Entries
    88
    Thanks
    482
    Thanked 808 Times in 527 Posts

    Default Making Friendly URLs

    Hotaru offers a friendly url method which you can turn on or off by setting it to true or false in Admin->Settings.

    Examples

    Friendly URLs OFF:

    myhotarusite.com/index.php?page=34
    myhotarusite.com/index.php?page=profile
    Friendly URLs ON:

    myhotarusite.com/name-of-the-post/
    myhotarusite.com/profile/
    Of course, as a plugin developer, you don't know whether the user has turned friendly URLs on or off, so you should use Hotaru's url() function instead of hard-coding the links:

    PHP Code:
    echo "<a href='" $h->url(array('page'=>'page_wanted')) . "'>Page Wanted</a> 
    You can use this one for Admin pages:

    PHP Code:
    echo "<a href='" $h->url(array('page'=>'page_wanted'), 'admin') . "'>Page Wanted</a> 
    Note that the rewrite rules for Admin in the htaccess file are quite limited, so to avoid problems (e.g. with pagination), it's safer to link directly with /admin_index.php?page=page_name.

    Passing parameters

    If a 'page' is not given, Hotaru will default to 'index'. With friendly urls turned off, you can just pass parameters by adding 'key' => 'value' pairs to the url() function, but here are some htaccess rules to consider when friendly urls are turned on.

    Code:
    RewriteCond &#37;{REQUEST_URI} !\.(css|php|png|jpg|gif|ico|js|inc|txt)$
    RewriteRule ^([^/]*)/?$ index.php?page=$1 [L]
    RewriteRule ^([^/]*)/([^/]*)/?$ index.php?$1=$2 [L]
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ index.php?page=$1&$2=$3 [L]
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ index.php?$1=$2&$3=$4 [L]
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ index.php?page=$1&$2=$3&$4=$5 [L]
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ index.php?$1=$2&$3=$4&$5=$6 [L]
    For urls with an odd number of parameters, the first is always the page name. The rest, and also those in urls with an even number of parameters, are 'key' => 'value' pairs. While not incredibly flexible, it does allow for plugin developers to use friendly urls without needing the end user to modify the htaccess file.
    Last edited by Nick; 01-06-2010 at 02:41 PM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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
  •