TinyPortal

Development => Feedback => Topic started by: PeterLawrence on September 13, 2008, 03:20:54 PM

Title: Clean URLs
Post by: PeterLawrence on September 13, 2008, 03:20:54 PM
Just wondering if there are any plans to introduce support for clean URLs into Tinyportal?
For example instead of http://index.php?page=MyArticle a web address such as http://index.php/Article/MyArticle could be used instead.
This kind of thing is supported by other content management systems  such as Wordpress and Drupal on Apache servers.

I found this article http://brian.moonspot.net/2007/10/04/forcetype-for-nice-urls-with-php/  which explains how to do this for Apache servers.

You need to create a php file with an appropriate filename (i.e "article") note the file extension is not required.

<?php
   
/* parse the URL */
   
$expl explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
   
$article_id $expl[count($expl)-1];
   
$arg_count count($expl);

   
/* if the right number of parameters send to smf */
   
if ($arg_count == 3)
   {
       
$_GET['page'] = $expl[count($expl)-1];
       include 
'index.php';
   }
   else
   {
      
header('HTTP/1.1 404 Not Found');
      
header('Status: 404 Not Found');
     exit();
   }
?>


And then add the following to the .htaccess file

<FilesMatch "^article$">
   ForceType application/x-httpd-php
</FilesMatch>


An alternative method is to use the .htaccess command RewriteRule.

The above code is only an initial prototype so any suggestions would be most appreciated.
Thanks

Title: Re: Clean URLs
Post by: bloc on September 13, 2008, 08:10:10 PM
I have certainly been thinking about it :)

I do have a site I am trying out exactly that. Instead of "site.com/index.php/page,23.html" which is the SMF way, I currently have "site.com/page/23.html" which is better to read and remember. But it has its bugs still, so I need to work more on it.
Title: Re: Clean URLs
Post by: eldacar on September 14, 2008, 04:37:22 AM
You can use my Pretty URLs mod, with the Extras package which has support for TP articles.

http://code.google.com/p/prettyurls/downloads/list
Title: Re: Clean URLs
Post by: PeterLawrence on September 15, 2008, 05:39:45 PM
An interesting mod.
However, it does have the problem of hiding subfolders if the board/topic option is used.
Maybe you should add the following to the .htaccess file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
which may solve this problem.

Also it would be nice if TP returned the 404 error if an article is not found.