Jump to Main Content
Content > XOOPS > xoRewriteModule
xoRewriteModule

xoRewriteModule is a Hack -- not a module -- for XOOPS 2.0.x and 2.3.x that allows for more readable URLs, and may help increase your search engine rankings.

Latest Version: 1.00 | Website (DuGruis)

Requires: Apache mod_rewrite module (as well as XOOPS, of course)

Installation

These instructions are for XOOPS 2.3.X (last done for 2.4.5), but generally should work for 2.0.x as well based on what I've read and researched. Not too bad overall, but still a hack. You should be an intermediate XOOPS user to pull this one off.

Clean Install

I started with the instructions by HowToDude. However, I ran into some problems here and there, so I had a bit of research. Below is the modified version of that article with other captured research integrated. Without numerous postings, I wouldn't have pulled this off as easily as I did. Some other links I used: URL Changer |

Upgrade

Haven't had to yet, but likely you just need to copy the updated files and see if there are any changes to the code. Always test before deploying on a production server, of course.


Rewrite URLs in XOOPS with xoRewriteModule (Howtodude.NET)

Before You Start

Before you start:

Installation and Configuration

For each module, you will need to follow these instructions. Note that newmoddir is the new directory name and oldmoddir is the existing directory name for the module being changed.

Recognize New Urls

First, you must allow recognition of the new URLs. This is done in your .htaccess file (create one if it doesn't exist). Include (or merge) the following lines into your root .htaccess file:

RewriteEngine On
RewriteRule ^newmoddir1/(.*)$ /modules/oldmoddir1/$1 [QSA,L]
RewriteRule ^newmoddir2/(.*)$ /modules/oldmoddir2/$1 [QSA,L]

for each module create a similar 2nd (or 3rd) line (but don't use the first line more than once).

Rewrite URLs

Next, make XOOPS rewrite the new URLs using the xoRewriteModule smarty plug-in. Edit your /header.php file, find this line (about line 67):

$xoopsTpl =& $xoTheme->template;

modify it like so:

$xoopsTpl =& $xoTheme->template;
//xoRewritemodule
$xoopsTpl->load_filter('output', 'xoRewriteModule');

Note: The HowToDude.net article suggested inserting at a location near the top, but in XOOPS 2.3.3, this caused a blank page, so per another post I added the lines just before the end of the file (just before the closing ?> ), but then I had problems with the cache. Then I noticed that one of the lines in the HowToDude article already existed, so I modfied it as I noted and it works properly it seems.

Plug-In Configuration

Lastly, you must edit the smarty plug-in configuration file to specify which modules the plug-in should rewrite URLs for. Edit /configs/xoRewriteModule.ini.php, and for each module, include a line like this:

[xoRewriteModule]
oldmoddir="newmoddir"

For example, assume you only want to rewrite the URLs of the module"tag" (from /modules/tag/ to /tags/).  Change:

[xoRewriteModule]
news="actualite"
newbb="forum"
wfdownloads="telechargement"
smartpartner="partenaires"
sitemap="plandusite"
formulaire="contact"
rss="filrss"
extgallery="galerie"

to:

[xoRewriteModule]
tag="tags"
* news="actualite"
* newbb="forum"
* wfdownloads="telechargement"
* smartpartner="partenaires"
* sitemap="plandusite"
* formulaire="contact"
* rss="filrss"
* extgallery="galerie"

The line tag="tags" defines the new URL of the tag module, and the asterisk comments out the other modules not affected. Edit this file as desired for new modules.

Check Working

Every thing should be working now. The URLs are rewritten and the internal links in XOOPS refer to the new, rewritten URLs.

Redirect Old Pages with PHP

However, the old URLs are still working as well and these probably remain indexed by search engines. To avoid duplicate content (and thus reduced rankings), you need to redirect these to their new location via 301-redirects (signaling browsers/search engines that files have moved permanently). Unfortunately, you can't do this in .htaccess as you will create an infinite loop, thus you must do this in the php code -- for each module (and for each file call you want to redirect).

if (strpos(getenv('REQUEST_URI'), '/modules/moddirname/') === 0) {
    $oldurl = getenv('REQUEST_URI');
    $newurl = str_replace("modules/moddirname", "newmodulename", $oldurl);
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: $newurl");
}

As an example, for the tag module, add the following code to /modules/tag/header.php (right at the top below the comments):

if (strpos(getenv('REQUEST_URI'), '/modules/tag/') === 0) {
    $oldurl = getenv('REQUEST_URI');
    $newurl = str_replace("modules/tag", "tags", $oldurl);
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: $newurl");
}

You will need to do something similar for each module (and depending upon the module, potentially in several files for each module). Realize that header location commands MUST come before any other output.

That's it: your URLs are rewritten and your old pages are redirected to the new ones.

XOOPS Start Module

If your XOOPS site starts on a single module, then you'll likely want to also include this in your .htaccess file. I haven't tested it, but found it in another post.

# To deal with XOOPS redirecting to module as startup
# (only if not doing the 301 moved permanently above)
RewriteCond %{REQUEST_URI} !^/.+/
RewriteRule ^$ /modules/startmoddir/ [L]
# to include root index.(php|html|htm) files
RewriteCond %{REQUEST_URI} !^/.+/
RewriteRule ^(index(.php|.html|.htm))?$ /modules/startmoddir/ [L]

Errors / Defects / Modifications

A few things I found while implementing this:

Plugin Error

I found a posting about an error in the Smart Plugin code. Fix these lines in the plug-in (change /modules/ to modules/):

$_SERVER['REQUEST_URI']  = str_replace( $value , 'modules/'.$key , @$_SERVER['REQUEST_URI'] ) ;
$_SERVER['HTTP_REFERER'] = str_replace( $value , 'modules/'.$key , @$_SERVER['HTTP_REFERER'] ) ;

XOOPS Core Changes

If you're like me, you also wanted to make changes to the URL for the profiles module. As such, because of the redirects used in the root core files, you'll have to rewrite those URLs (or redirect the old pages with PHP as outlined above - something I have yet to accomplish). The core files to change for the Profiles module are: edituser.php, lostpass.php, register.php, user.php, userinfo.php. For the PM module: pmlite.php, readpmsg.php, viewpmsg.php. It looks like backend.php and pda.php also need some changes for this as well or these will all use the /modules/modulename URLs. Joy!

Others

I looked at other solutions, too, of course. Based on some reviews, posts, write-ups and a seemingly lack of documentation and the appearance of abandonment (hard to find the official release), I haven't pursued implementing them. Also, I'm not sure they are actually any better than the xoRewriteModule. From what I understand, first was Reynaldo's ShortURLs and then sim_suin's Simplified URLs (based on ShortURLs). From what I've read, both have problems. xoRewrite works pretty well, and is the proper solution using Smarty IMHO. Links for Simplified URLs: Simplified URLs | Simplified URLs

Interestingly there is a SEO hack for CBB (aka newbb) 3.08: SEO Hack for CBBSEO Hack for CBB . This also appears adaptable to other modules fairly easily. Might be worth trying. I did read that it had problems with xLanguage, but has code for MultiLanguage.


Other Pages
Previous Page WF-Channel Content Module AltSys - Block/Template Management Next Page
 
Comments are solely the opionion of the author and not to be construed as the opinion of anyone else.

Poster Thread
Anonymous
Posted: 2011/2/19 12:15  Updated: 2011/3/12 3:10
 Re: xoRewriteModule
Hi!

It's possible dowmload the files!

Thanks
Reply

Poster Thread
me
Posted: 2011/3/12 3:12  Updated: 2011/3/12 3:12
Administrator
Joined: 2005/2/26
From: Austin, TX
Posts: 85
Online!
 Re: xoRewriteModule
Sorry for the delay; I updated the link as the author's site changed modules and thus the link changed.
Reply

Poster Thread
Anonymous
Posted: 2011/6/15 19:07  Updated: 2011/7/27 15:08
 Re: xoRewriteModule
Link is broken !
Reply

Poster Thread
Anonymous
Posted: 2012/2/18 22:05  Updated: 2012/6/3 17:46
 Re: xoRewriteModule
the download link is broken for Dugris's site
Reply
Login
 

 

 

(c) 2006-2007 - Mark Boyden
Privacy - Legal Stuff - Contacts