1
Bassman
Using mod_rewrite to remove "modules" from URL's?
  • 2005/9/14 3:08

  • Bassman

  • Friend of XOOPS

  • Posts: 1272

  • Since: 2003/5/23


I know it's possible to use mod_rewrite in .htaccess files in Apache servers to create more search-engine friendly URL's, but all I want to do is change http://www.mysite.com/modules/news etc to http://www.mysite.com/news, ie remove /modules from the URL.(but for all/any modules)

Any .htaccess/mod_rewrite gurus out there that can give me the specific lines to add to my .htaccess file?

2
WarDick
Re: Using mod_rewrite to remove "modules" from URL's?
  • 2005/9/14 4:56

  • WarDick

  • Just can't stay away

  • Posts: 890

  • Since: 2003/9/13


I have noticed that many of the Japanese sites are doing this. How?
Urging XOOPS to be the Best It Can Be.
Richard......

3
Bassman
Re: Using mod_rewrite to remove "modules" from URL's?
  • 2005/9/14 7:46

  • Bassman

  • Friend of XOOPS

  • Posts: 1272

  • Since: 2003/5/23


I've noticed too. I'm sure someone will be able to enlighten us?

4
chapi
Re: Using mod_rewrite to remove "modules" from URL's?
  • 2005/9/14 8:03

  • chapi

  • Theme Designer

  • Posts: 611

  • Since: 2002/1/22


It must be something like this ...

RewriteEngine on
RewriteRule 
^(.*) modules/$[L]


So every input will get /modules before it, no? The only problem are the normal XOOPS links, that already have the "modules" in it.

So I think there also have to be some php code that sanitizes XOOPS internal urls.

5
Bassman
Re: Using mod_rewrite to remove "modules" from URL's?
  • 2005/9/14 21:57

  • Bassman

  • Friend of XOOPS

  • Posts: 1272

  • Since: 2003/5/23


Thanks Chapi, tried that and get a 500 error.

Any other suggestions?

6
just4fun
Re: Using mod_rewrite to remove "modules" from URL's?
  • 2005/9/14 23:01

  • just4fun

  • Just popping in

  • Posts: 55

  • Since: 2003/7/28


Bassman

I did lot of customization on my site to achieve 100% SEO urls... but it requires changes to include/common.php file and your module files.

My work

Step 1

Replace all your links in a module with identible key for that module and make it as simple html link

example : - News

news.html
news__.html
news_view_.html

Step 2

Xoops uses request Url to identify which module user is trying to access and gets a module handler on that. So we need to change that as our new seo ready links wont be having any modules//.

Search for this code in include/common.php

if (file_exists('./xoops_version.php')) {

        
$url_arr explode('/',strstr($xoopsRequestUri,'/modules/'));
        
$module_handler =& xoops_gethandler('module');


next to that you need to do some thing like this..

// default behaviour
        
if(is_array($url_arr) && count($url_arr) > 1) {
           
$xoopsModule =& $module_handler->getByDirname($url_arr[2]);
        } else {
          if(
strpos($xoopsRequestUri,"news") != false) {
               
$xoopsModule =& $module_handler->getByDirname("news");
          } else if(
strpos($xoopsRequestUri,"forums") != false) {
               
$xoopsModule =& $module_handler->getByDirname("forums");
          } 
        .....
        unset(
$url_arr);


Step 3

Prepare your .htaccess file

RewriteEngine on
RewriteRule 
^index.html index.php
RewriteRule 
^newshtml /modules/news/index.php
RewriteRule 
^news_[A-Za-z]*_([0-9][0-9]*).html /modules/news/index.php?storytopic=$1
RewriteRule 
^news_view_([0-9][0-9]*).html /modules/news/article.php?storyid=$1


Thats it and your site will have 100% seo html links

Some of the working examples on my site

http://www.dealwithdeals.com/computers-deals-2.html ( using deals module )

http://www.dealwithdeals.com/latest_deals.html ( using deals module )

http://www.dealwithdeals.com/stores.html ( using stores module )


If any of you guys are interested in this hack lemme know i'll publish steps in detail...
In theory there is no difference between theory and practice but in practice it does...

7
Bassman
Re: Using mod_rewrite to remove "modules" from URL's?
  • 2005/9/14 23:44

  • Bassman

  • Friend of XOOPS

  • Posts: 1272

  • Since: 2003/5/23


Very interesting! But I will need more details :) Best if you consider me a complete novice in this area.

Thanks for your help just4fun!

8
otr222
Re: Using mod_rewrite to remove "modules" from URL's?
  • 2005/9/15 17:07

  • otr222

  • Not too shy to talk

  • Posts: 124

  • Since: 2005/5/13


Quote:

just4fun wrote:
If any of you guys are interested in this hack lemme know i'll publish steps in detail...


I'd sure be interested in seeing that, as I'm sure many others would. (nice site by the way)

Thanks

9
Bassman
Re: Using mod_rewrite to remove "modules" from URL's?
  • 2005/9/15 21:44

  • Bassman

  • Friend of XOOPS

  • Posts: 1272

  • Since: 2003/5/23


*bump*

10
just4fun
Re: Using mod_rewrite to remove "modules" from URL's?
  • 2005/9/15 23:26

  • just4fun

  • Just popping in

  • Posts: 55

  • Since: 2003/7/28


Sorry for the delay, i was busy with my work.

I'll prepare news module with all the hacks and post the zip file by tomorrow morning.
In theory there is no difference between theory and practice but in practice it does...

Login

Who's Online

426 user(s) are online (259 user(s) are browsing Support Forums)


Members: 0


Guests: 426


more...

Donat-O-Meter

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

Latest GitHub Commits