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.
GeneralThis is about changing URL's like
http://www.yourdomain.com/modules/smartsection/item.php?itemid=1 in URL's like
http://www.yourdomain.com/widgets.html.
I'm using the Apache Server Mod Rewrite (or mod_rewrite )function. See
http://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 http://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:
http://www.yourdomain.com/index.php?lang=en becomes
http://www.yourdomain.comand
http://www.yourdomain.com/index.php?lang=nl becomes
http://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 http://www.yourdomain.com/widgets/ or http://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
http://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=1 [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
http://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=2 [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]