1
technigrafa
Rewriting module URLs

We have a site that we need to make the urls look different on. I assume the only way to do this is with a mod rewrite, but I am not sure how to pull it off.

We need to make urls like:
www.sample.com/modules/tinycontent1/index.php?ID=12

Look something like:
www.sample.com/teachers/12.html

And if someone types in the latter url, it needs to redirect to the previous.

I have tried a mod rewrite hack I found here that successfully changes urls to be html files for better SEO, but I want to also change the names of the modules in the new url--like in the example above: "tinycontent1" into "teachers." So the urls make more sense to users.

I need to do this with several different modules, and I would rather not hack each module to use the name that we want, as that is a pain and I was hoping there would be an easier way to do it using mod_rewrite.

Any experts out there have an idea how to do that?

2
disky
Re: Rewriting module URLs
  • 2005/11/23 9:30

  • disky

  • Just popping in

  • Posts: 90

  • Since: 2003/10/31


Hi there

I have this in my .htaccess file: (i added comments for this example, coments starts with -- remove before adding to your own .htaccess)


RewriteEngine On
RewriteBase /

--This line makes it possible to write:
--www.domain.com/article/17
--instead of
--www.domain.com/fsArticle/index.php?articleid=17
RewriteRule ^article/([0-9]+)$ /modules/fsArticle/index.php?articleid=$1 [L]

--This line makes it possible to write (search engine optimization):
--www.domain.com/article/17/This_Is_a_very_LOOOOOONG_URL
RewriteRule ^article/([0-9]+)/.*$ /modules/fsArticle/index.php?articleid=$1 [L]

--this is the same just for categories.
RewriteRule ^category/([0-9]+)$ /modules/fsArticle/index.php?categoryid=$1 [L]


I also had to change 1 line in includes/common.php
from:
$xoopsRequestUri = $_SERVER[ 'REQUEST_URI' ]; // Deprecated (use the corrected $_SERVER variable now)
to:
$xoopsRequestUri = $_SERVER[ 'SCRIPT_NAME' ];


I have no clue why they did not do this per default in the core ?

But at least it works.
You can see it in action here:
http://www.xray-mag.com/index.php

I hope it helps, else just write again.

I think your solution would be something like:
RewriteRule ^teachers/([0-9]+).html$ /modules/tinycontent1/index.php?ID=12$1 [L]

Best regards
Søren Reinke

3
sikey
Re: Rewriting module URLs
  • 2005/11/23 9:52

  • sikey

  • Not too shy to talk

  • Posts: 151

  • Since: 2003/4/29


This could become a very useful thread for people who want to optimize their website for SE's...
It would be nice if we could have examples for all available modules.

For instance, me myself, i'm looking for the code to change plain mydownloads modules from

http://www.domain.com/modules/mydownloads/singlefile.php?lid=134
to
http://www.domain.com/Internet/E-mail ... Bulk-Email-Software.shtml
domain category subcategory program name

I think this might be useful for many people...

thx in advance to all modrewrite gurus out there that might be able to help

4
Bassman
Re: Rewriting module URLs
  • 2005/11/23 9:53

  • Bassman

  • Friend of XOOPS

  • Posts: 1272

  • Since: 2003/5/23


Nice site, you would not know it was a XOOPS site - nice customisation!

I wanted to change URLs from http://www.mysite.com/modules/edito/content.php?id=1
to http://www.mysite.com/mynameformodule/id=1 and
http://www.mysite.com/modules/news/ to http://www.mysite.com/news/

Can you give me a specific rewrite rule for this?

5
davidl2
Re: Rewriting module URLs
  • 2005/11/23 10:04

  • davidl2

  • XOOPS is my life!

  • Posts: 4843

  • Since: 2003/5/26


Disky - that's a very very nice site indeed!

I'll try this mod-rewrite hack myself - as it seems a very handy trick to use... I don't really understand it though :)

(Regarding your site - please submit it to StudioCs website competition... it's a very nice piece of work!)

6
disky
Re: Rewriting module URLs
  • 2005/11/26 13:02

  • disky

  • Just popping in

  • Posts: 90

  • Since: 2003/10/31


Quote:

Bassman wrote:
Nice site, you would not know it was a XOOPS site - nice customisation!

I wanted to change URLs from http://www.mysite.com/modules/edito/content.php?id=1
to http://www.mysite.com/mynameformodule/id=1 and
http://www.mysite.com/modules/news/ to http://www.mysite.com/news/

Can you give me a specific rewrite rule for this?



Glad you like the site, but the new design that will be online in a few days is even better (i think).

I think you should add the following to your .htaccess file:

RewriteEngine On
RewriteBase /
RewriteRule ^mynameformodule/([0-9]+)$ /modules/edito/content.php?id=$1 [L]
ReWriteRule ^news /modules/news [L]


I made one little change,
Instead of: http://www.mysite.com/mynameformodule/id=1
I think http://www.mysite.com/mynameformodule/1
is better for search engines

If you want to be able to do
http://www.mysite.com/mynameformodule/1/ArticleHeadLine

change:
RewriteRule ^mynameformodule/([0-9]+)$ /modules/edito/content.php?id=$1 [L]
to
RewriteRule ^mynameformodule/([0-9]+)/.*$ /modules/edito/content.php?id=$1 [L]

Hope it works :)

7
disky
Re: Rewriting module URLs
  • 2005/11/26 13:04

  • disky

  • Just popping in

  • Posts: 90

  • Since: 2003/10/31


Quote:

davidl2 wrote:
Disky - that's a very very nice site indeed!

I'll try this mod-rewrite hack myself - as it seems a very handy trick to use... I don't really understand it though :)

(Regarding your site - please submit it to StudioCs website competition... it's a very nice piece of work!)


Hi there

Glad you like it :)

Don't worry i don't really understand it myself, but it works :)

'StudioCs website' do you have an URL ?

Then i'll submit it when the new design is online.

Now the site should look more like a dive magazine :)

8
davidl2
Re: Rewriting module URLs
  • 2005/11/26 13:30

  • davidl2

  • XOOPS is my life!

  • Posts: 4843

  • Since: 2003/5/26


Check this news item for more information
https://xoops.org/modules/news/article.php?storyid=2704

9
disky
Re: Rewriting module URLs
  • 2005/11/26 14:56

  • disky

  • Just popping in

  • Posts: 90

  • Since: 2003/10/31


If anyone need a mod_rewrite for 'mylinks' modules

here it is:

RewriteRule ^link/([0-9]+)/([0-9]+)$ /modules/mylinks/visit.php??cid=$1&lid=$2 [L]

Instead of:
www.mydomain.com/modules/(mylinks/visit.php?cid=17&lid=22

you can now write:
www.mydomain.com/link/17/22

10
disky
Re: Rewriting module URLs
  • 2005/11/26 14:57

  • disky

  • Just popping in

  • Posts: 90

  • Since: 2003/10/31


Quote:

davidl2 wrote:
Check this news item for more information
https://xoops.org/modules/news/article.php?storyid=2704


Thanks david12 :)

Login

Who's Online

54 user(s) are online (33 user(s) are browsing Support Forums)


Members: 0


Guests: 54


more...

Donat-O-Meter

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

Latest GitHub Commits