Spiga

URL rewrite for XOOPS news module

by Gabi Solomon

For this example we will considet that the nes module name is PS2. You can adapt this to whatever you want to.

First lets start by adding the rewrite Rules :

# Welcome to Windows IIS URL Rewriting! Below are the rules[ISAPI_Rewrite]# test rewrite StateRewriteRule /testrewrite.html / [I,L]      

# PS2 news Topic Rewrite : /ps2-c191-test-Article.html      

RewriteRule ^.*/ps2-c([0-9]*)-[^/]+.html /modules/news/index.php?storytopic=$1 [I,L]      

# PS2 news Rewrite : /ps2-191-test-Article.html      

RewriteRule ^.*/ps2-([0-9]*)-[^/]+.html /modules/news/article.php?storyid=$1 [I,L]
# Welcome to Linux Url-Rewrite 

# PS2 news Topic Rewrite : /ps2-c191-test-Article.html
RewriteRule ^.*/ps2-c([0-9]*)-[^/]+.html /modules/news/index.php?storytopic=$1 [L]  

# PS2 news Rewrite : /ps2-191-test-Article.html
RewriteRule ^.*/ps2-([0-9]*)-[^/]+.html /modules/news/article.php?storyid=$1 [L]

Next we need to add a new function to the module so we open /modules/news/include/functions.php and add a new function to the end of the file right before the php end tag ?>

/** * Create an url safe text*      

* @package News      

* @author Gabriel Solomon ( solomongaby at yahoo.com  )      

* @copyright (c) GSDesign www.gsdesign.ro      

*/      

function make_url($text)      

{  $urlName = strtolower($text);      

$trans = array(
" " => "-",
"/" => "",
"'" => "",
'"' => "",
);      

$trans[trim( " / " )] = "";      

$urlName= strtr($urlName, $trans);      

return $urlName;      

}

After this we need to register our new function as a smarty modifier. So we open /class/template.php and after

		$this->Smarty();

we add

		$this->register_modifier("make_url", "make_url");

Now we start to modify files :
/modules/news/class/class.newsstory.php
The modifications are saved in the file class.newsstory.php available in this file :
class.newsstory.php Modifications

/module/news/templates/news_article.html
The modifications are saved in the file news_article.html available in this File
news_article.htm Modifications

Hope you will find this usefull.

We are working on an installer and as soon as we have it you will find it here.

Awaiting you’re comments and reviews.

Related Posts

  • contact me on MSN or yahoo ... see the contacts details in my about page

  • hi
    I try. Make all modify yo all files give me error. File not Found 404 . Please Help me. What i can do. Where i can check??

    Thanks
  • Márcio Pereira : I have answered you on the XOOPS website.
    If you have any more problems contact me on any IM service that you can find in my profile
  • I\'ve tried your hack but with no success.

    I use XOOPS 2.2.4, news 1.53 and my server is running Apache.

    URLs are rewritten but when I click on them I get 404 error.

    I use a subdirectory folder (http://www.mistershare.org/home/). Would be the reason?

    Rewritten URL: http://www.mistershare.org/home/noticia-132-tra...
    Original URL: http://www.mistershare.org/home/modules/news/ar...

    I have a doubt: Do I need to put the Rewrite rules in htaccess inside news folder (/modules/news/.htaccess) or in Xoops root directory (/.htaccess)?

    Thanks in advance!
  • Problem Solved ... sily me i forget the comas :).
    The code above has been updated.
  • hello,
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting \\\')\\\' in /home/sites/XXXXX.com/public_html/modules/news/include/functions.php on line 618

    here is bug
    using your code i think it for replacing \\
  • thank you for the heads up :)
  • typo for this part:




    ORIGINAL


    Now we start to modify files :


    /modules/news/include/class/class.newsstory.php


    The modifications are saved in the file class.newsstory.php available in this file :


    class.newsstory.php Modifications






    CORRECTON


    Now we start to modify files :


    /modules/news/class/class.newsstory.php


    The modifications are saved in the file class.newsstory.php available in this file :


    class.newsstory.php Modifications



blog comments powered by Disqus