Fork me on GitHub
Get XOOPS XOOPSXOOPS FAQFAQ ForumsForums NewsNews ThemesThemes ModulesModules
New Posts New Topics All Posts All Forums Index General Modules Themes Development International XOOPS.org

Search

Learn XOOPS Core

Donat-O-Meter

Make donations with PayPal!
Stats
Goal: $100.00
Due Date: Sep 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00

Local Support

Advertisement

XOOPS Code hosted on SourceForge

Cumulus Tag Cloud

- 2 2.5 2.6 3.0 4 6 2013 Abuse adslight Android AntiHarvesting AntiMalUser AntiSpam API Apple Battlefield billige Blocks Bootstrap Captcha cell cent chronolabs CHUNG Clicks content CĂN demo docek download Dresses evden eve facebook Fat floor Food for free Gateway Google Guide herre Home Honeypot HP Human HỘ IP iPhone jQuery Language List log Loss mobile module modules Monster new newbb news NHÀ online PARK phone PHP Prevention profile project Protector publisher RESIDENCE responsive review Rights rmcommon security Sentry site Smartphone Smoking Solution Spam Studio tag tags tdmcreate template The Theme themes web weight Wishcraft xoops Xortify

New Users

Registering user

# 137717

SLNK214324

Welcome to XOOPS!




Bottom   Previous Topic   Next Topic  Register To Post

(1) 2 3 4 5 »


#1 Posted on: 2009/5/27 9:58 HOWTO: xoRewriteModule - Simplified, Short URLs (remove /modules)
xoRewriteModule is a Hack -- not a module -- for XOOPS 2.0.x and 2.3.x that allows for somewhat more readable URLs, and may help increase your search engine rankings (disputed to a degree). As hacks go, this one is pretty easy because you really aren't touching core code except for one line in one file (header.php). However, you do need to know what you are doing in .htaccess with the mod_rewrite apache module and have some basic intermediate skills with XOOPS. I recently did this on my sites, and it went very well.

The notes below are the XOOPS-forum-ified version of my notes (limited in formatting features). You may find it easier to visit my notes on the xoRewriteModule, (what I've posted here with any future updates), but I always try to contribute my knowledge back here on X.o to be easily found here.

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.3.3), 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:
- Backup your website!
- check if you have an Apache webserver with mod_rewrite enabled (required)
- Download the module. Upload the directories/files in the unpacked xoRewrite directory to the XOOPS root.

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/$[QSA,L]
RewriteRule ^newmoddir2/(.*)$ /modules/oldmoddir2/$[QSA,L]
create a similar 2nd (or 3rd) line for each module (but don't duplicate the first line).

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 modified it as I noted and it seems to work properly.

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). And this is where the real hack occurs. You don't have to do this if it's a new site, though, since those legacy links aren't indexed anywhere.

Generic Example Code:
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'] ) ;

Other Solutions
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 CBB | SEO 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.

Good luck!

Top


Pessimists see difficulty in opportunity; Optimists see opportunity in difficulty. --W Churchill

XOOPS: Latest | Debug | Hosting and Web Development
mboyden
Moderator
Moderator
Joined:
2005/3/9 12:07
From Austin, TX (USA)
Group:
Registered Users
Posts: 475
(Show More) (Show Less)


#2 Posted on: 2009/5/27 10:55 Re: HOWTO: xoRewriteModule - Simplified, Short URLs (remove /modules)
Thanks for this Mark

;o)

Top


RoadNoize | The Goss | OzMS | NQR! | MS Buzz
DarinAllan
Friend of XOOPS
Friend of XOOPS
Joined:
2005/5/18 7:48
From Australia
Group:
Registered Users
Posts: 472
(Show More) (Show Less)


#3 Posted on: 2009/5/28 7:23 Re: HOWTO: xoRewriteModule - Simplified, Short URLs (remove /modules)
mboyden,

awesome explanation, many thanks !!!

Top


HispaXoops | Xoops España

That's the way i like it! | Nada mejor que una Alhambra bien helada con aceitunas...
DonCurioso
Quite a regular
Quite a regular
Joined:
2009/3/1 7:13
From España
Group:
Registered Users
Posts: 230
(Show More) (Show Less)


#4 Posted on: 2009/5/29 1:09 Re: HOWTO: xoRewriteModule - Simplified, Short URLs (remove /modules)
Yes, thanks for that Mark, you have really explained it well.

Top


Xoops CMS design
Membership based website design
Shiva
Quite a regular
Quite a regular
Joined:
2006/7/9 8:47
From England
Group:
Registered Users
Posts: 245
(Show More) (Show Less)


#5 Posted on: 2009/5/29 1:15 Re: HOWTO: xoRewriteModule - Simplified, Short URLs (remove /modules)
I suppose if we wanted each page for each module to be "URL friendly" then we would need to do a hack each module?

Or could we do it at a higher level (in one place) somehow?

For example to achieve the following effect for URLs:
http://www.xoops.org/downloads/1/themes/2/morpho2.html

Cheers!

Top


Xoops CMS design
Membership based website design
Shiva
Quite a regular
Quite a regular
Joined:
2006/7/9 8:47
From England
Group:
Registered Users
Posts: 245
(Show More) (Show Less)


#6 Posted on: 2009/5/29 5:16 Re: HOWTO: xoRewriteModule - Simplified, Short URLs (remove /modules)
Hello everybody, i tested this hack but it does not work.

then, the url of the links are rewritten correctly but when I click on a link gives me an error message.

for example with the xpetitions module that I want to call 'petizioni' when I click on the link http://localhost/petizioni returns a page which says

The requested URL /modules/xpetitionswas not found on this server.


my .htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteRule 
^petizioni/(.*)$ /modules/xpetitions/$[QSA,L]


how can I solve?
tnx

Urban

Top


http://www.ultrasonica.it
http://www.noisecollective.net
urbanspacema
Quite a regular
Quite a regular
Joined:
2004/9/19 15:25
From Italy
Group:
Registered Users
Posts: 265
(Show More) (Show Less)


#7 Posted on: 2009/5/29 5:20 Re: HOWTO: xoRewriteModule - Simplified, Short URLs (remove /modules)
ps.
it works if my .htaccess is
Options +FollowSymlinks
RewriteEngine On
RewriteRule 
^petizioni/(.*)$ http://localhost/modules/xpetitions/$1 [QSA,L]



Update:

My mistake, I don't have updated these two lines

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


Top


http://www.ultrasonica.it
http://www.noisecollective.net
urbanspacema
Quite a regular
Quite a regular
Joined:
2004/9/19 15:25
From Italy
Group:
Registered Users
Posts: 265
(Show More) (Show Less)


#8 Posted on: 2009/6/17 10:15 Re: HOWTO: xoRewriteModule - Simplified, Short URLs (remove /modules)
What's wrong here?
RewriteRule ^sitemap/(.*) /modules/sitemap/$[QSA,L]


Everything is set up correctly inside the other files, I know because it works with all other modules.

The above would work too, IF there wouldn't be a file called sitemap.xml on the server (xoops root). How to prevent this failure?

Top

frankblack
Just can't stay away
Just can't stay away
Joined:
2005/6/13 3:03
From D-Schiefbahn
Group:
Registered Users
Posts: 785
(Show More) (Show Less)


#9 Posted on: 2009/6/17 10:25 Re: HOWTO: xoRewriteModule - Simplified, Short URLs (remove /modules)
Quote:
The above would work too, IF there wouldn't be a file called sitemap.xml on the server (xoops root). How to prevent this failure?


I had a similar issue with the XOOPS images directory when i renamed xcgal to images, the only solution i have is to call the sitemap module soomething else like site-map or something like that.

Top


My website and blog.

Whitlawburn Community Resource Centre
playsome
Not too shy to talk
Not too shy to talk
Joined:
2009/4/15 15:38
Group:
Registered Users
Posts: 197
(Show More) (Show Less)


#10 Posted on: 2009/6/17 10:55 Re: HOWTO: xoRewriteModule - Simplified, Short URLs (remove /modules)
Use these two rules:
^sitemap.(.*) /sitemap.$[L]
^
sitemap/(.*) /modules/sitemap/$[L]




Top


The art of asking questions.
ghia
Community Support Member
Community Support Member
Joined:
2008/7/3 14:19
From Belgium
Group:
Registered Users
Posts: 4946
(Show More) (Show Less)




(1) 2 3 4 5 »



You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You can vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.

[Advanced Search]