TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 790
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 452
  • Total: 452

Clean URLs

Started by PeterLawrence, September 13, 2008, 03:20:54 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PeterLawrence

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


bloc

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.

eldacar

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

PeterLawrence

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.



This website is proudly hosted on Crocweb Cloud Website Hosting.