1
Dona_Brasil
URL Rewriting for XOOPS - Tips and Tricks

Another webmaster mailed me:

Quote:

I like your url rewrite of your pages and would like to do the same on my new site.
Can you send me an example of one page to show me how you did the url rewrite for
the SmartSecition modul?


I did different things for different pages. I'm no specialist in this matter but I got my solutions from other people who like to share information. Now it is my turn to share: Besides: I'm curious if other members of this community have more useful tips and tricks on URL Rewrite

Using the tips below, I had nearly as much control over my URL's as Joomla's Open SEF.

General

This is about changing URL's like www.yourdomain.com/modules/smartsection/item.php?itemid=1 in URL's like www.yourdomain.com/widgets.html.

I'm using the Apache Server Mod Rewrite (or mod_rewrite )function. See www.modrewrite.com for more detailed info on mod rewrite.

The phrase

RewriteEngine On


should be included on top of the .htaccess file if you want to enable URL Rewrite

Redirecting yourdomain.com to www.yourdomain.com

Add this code to the .htaccess file in the root of your website.

RewriteCond %{HTTP_HOST} !^www.yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R,L]



Start page in different languages for XLanguage

Intention: www.yourdomain.com/index.php?lang=en becomes www.yourdomain.com

and www.yourdomain.com/index.php?lang=nl becomes www.yourdomain.com/nl/

Add something like this to your .htaccess file:

# English
RewriteRule ^en$ / [R=301]
RewriteRule ^en/$ / [R=301
DirectoryIndex index.php?lang=en
# Dutch
RewriteRule ^nl$ /nl/ [R=301]
RewriteRule ^nl/$ /index.php?lang=nl [QSA,L]


Avoid double content by adding something like this to the file /index.php :

// redirect to avoid double content
if(strpos(getenv('REQUEST_URI'), '/index.php?lang=nl') === 0

 
header("HTTP/1.1 301 Moved Permanently");
 
header("Location: http://www.yourdomain.com/nl/");

elseif(
strpos(getenv('REQUEST_URI'), '/index.php?lang=en') === 0

 
header("HTTP/1.1 301 Moved Permanently");
 
header("Location: http://www.yourdomain.com/");

elseif(
strpos(getenv('REQUEST_URI'), '/index.php') === 0

 
header("HTTP/1.1 301 Moved Permanently");
 
header("Location: http://www.yourdomain.com/");
}



Rewriting the URL’s of SmartSection pages like www.yourdomain.com/widgets/ or www.yourdomain.com/widgets/blue-widgets.html

Read the instruction for rewriting URL’s in SmartSection.

I don’t use this for my weblog, ony for my static pages. For my weblog, I use the general instructions that come with SmartSection. I cloned the module to have allow various installations.

In order to get www.yourdomain.com/widgets/, add something like this for each URL to your .htaccess file:

RewriteRule ^widgets$ /widgets/ [R=301]
RewriteRule ^widgets/$  modules/smartsection/seo.php?seoOp=item&seoArg=[QSA,L]


or something like this for multilingual sites:
RewriteRule ^widgets$ /widgets/ [R=301]
RewriteRule ^widgets/$  modules/smartsection/seo.php?seoOp=item&seoArg=1&lang=en [QSA,L]


In order to get www.yourdomain.com/widgets/blue-widgets.html , add something like this for each URL to your .htaccess file:

RewriteRule ^widgets/blue-widgets.html$  modules/smartsection/seo.php?seoOp=item&seoArg=[QSA,L]


Or something like this for multilingual sites:
RewriteRule ^widgets/blue-widgets.html$  modules/smartsection/seo.php?seoOp=item&seoArg=2&lang=en [QSA,L]


Keep some structure in your .htaccess, it makes life easy:

# ENGLISH
# CATEGORY widgets
RewriteRule widgets $ /widgets/ [R=301]
RewriteRule widgets/$  modules/smartsection/seo.php?seoOp=item&seoArg=1&lang=en [QSA,L]
RewriteRule widgets/blue-widgets.html$  modules/smartsection/seo.php?seoOp=item&seoArg=2&lang=en [QSA,L]
RewriteRule widgets /green-widgets.html$  modules/smartsection/seo.php?seoOp=item&seoArg=3&lang=en [QSA,L]
# DUTCH
# CATEGORY pruiken
RewriteRule nl/pruiken $ /nl/pruiken [R=301]
RewriteRule pruiken/$  modules/smartsection/seo.php?seoOp=item&seoArg=4&lang=nl [QSA,L]
RewriteRule nl/pruiken/blauwe-pruiken.html$  modules/smartsection/seo.php?seoOp=item&seoArg=5&lang=nl [QSA,L]
RewriteRule nl/pruiken/groene-pruiken.html$  modules/smartsection/seo.php?seoOp=item&seoArg=6&lang=nl [QSA,L]

2
hervet
Re: URL Rewriting for XOOPS - Tips and Tricks
  • 2006/11/22 12:28

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


Thiw will do an EXCELLENT article ?

3
Will_H
Re: URL Rewriting for XOOPS - Tips and Tricks
  • 2006/11/22 12:40

  • Will_H

  • Friend of XOOPS

  • Posts: 1786

  • Since: 2004/10/10


**COUCH** core **COUGH**

4
JMorris
Re: URL Rewriting for XOOPS - Tips and Tricks
  • 2006/11/24 0:27

  • JMorris

  • XOOPS is my life!

  • Posts: 2722

  • Since: 2004/4/11


Bookmarked! Excellent Tutorial!

I'll be giving this a try on the new site I'm working on, XOOPSinfo. I'm going for SEF URLs on all modules and your tips and tricks look like they will do just what I'm looking for.

Thanks!

James
Insanity can be defined as "doing the same thing over and over and expecting different results."

Stupidity is not a crime. Therefore, you are free to go.

5
Herko
Re: URL Rewriting for XOOPS - Tips and Tricks
  • 2006/12/3 13:27

  • Herko

  • XOOPS is my life!

  • Posts: 4238

  • Since: 2002/2/4 1


Excellent tutorial indeed!

Herko

6
Ronaldus
Re: URL Rewriting for XOOPS - Tips and Tricks
  • 2006/12/4 9:39

  • Ronaldus

  • Friend of XOOPS

  • Posts: 389

  • Since: 2004/5/8 1


WoW!!
Indeed great Dona!!
I feel a cough coming too, you infected me Will...

7
trainboy72
Re: URL Rewriting for XOOPS - Tips and Tricks
  • 2006/12/4 15:32

  • trainboy72

  • Just popping in

  • Posts: 3

  • Since: 2006/12/4


Thanks for that, I was only editing the robots file and paying no attention to htaccess, good work.

8
Dona_Brasil
Re: URL Rewriting for XOOPS - Tips and Tricks

Thanks folks, great to see that much enthousiasm!

Success with rewriting, and don't forget to show off your sites when you are ready!

9
limecity
Re: URL Rewriting for XOOPS - Tips and Tricks
  • 2006/12/6 1:08

  • limecity

  • Friend of XOOPS

  • Posts: 1602

  • Since: 2003/7/6 0


is this applicable to cbb module?
http://www.mounthiking.com
all your hiking gears and gadgets


10
Dona_Brasil
Re: URL Rewriting for XOOPS - Tips and Tricks

Quote:

limecity wrote:
is this applicable to cbb module?


No, CBB contains user added content, this way of rewriting URL's requires control by a webmaster as the .htaccess file needs to be adapted.

Login

Who's Online

212 user(s) are online (123 user(s) are browsing Support Forums)


Members: 0


Guests: 212


more...

Donat-O-Meter

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

Latest GitHub Commits