Lunarpages Web Hosting Forum

Author Topic: URL rewrite  (Read 3301 times)

Offline sureshmulagala

  • Spaceship Captain
  • *****
  • Posts: 116
    • http://www.shopperbag.com
URL rewrite
« on: March 08, 2004, 03:34:33 AM »
Hi,

Sorry, Im a bit new on this stuff, but was just going through some papers on url rewriting and modifying some configs for that....

i have my jsp pages which look something like

http://myhomepage.com/mypage.jsp?listid=3
http://myhomepage.com/mypage.jsp?listid=56
http://myhomepage.com/mypage.jsp?listid=345
etc etc.....

Now ive read somewhere that I can get the url rewritten as

http://myhomepage.com/mypage/3.html
http://myhomepage.com/mypage/56.html
http://myhomepage.com/mypage/345.html

though the .html extension is to trick the browser url for a possible hacker..

Can anyone please help me find out a step by step guide on how to achieve this? will greatly appreciate....
Bid, Buy or Sell for Free
www.shopperbag.com

Priest

  • Guest

Offline sureshmulagala

  • Spaceship Captain
  • *****
  • Posts: 116
    • http://www.shopperbag.com
URL rewrite
« Reply #2 on: March 08, 2004, 05:12:09 AM »
thanks steve...helped a lot....
Bid, Buy or Sell for Free
www.shopperbag.com

Offline sureshmulagala

  • Spaceship Captain
  • *****
  • Posts: 116
    • http://www.shopperbag.com
URL rewrite
« Reply #3 on: March 08, 2004, 05:23:14 AM »
just a quick one again

this worked fine when i wanted to change

www.mydomain.com/jsp/mypage.jsp?id=123 to
www.mydomain.com/123.html

by using

RewriteEngine on
RewriteRule ^([^/]+)\.html$ jsp/mypage.jsp?id=$1

but how do i achieve this?

www.mydomain.com/categories/123.html

any clues?
Bid, Buy or Sell for Free
www.shopperbag.com

Priest

  • Guest
URL rewrite
« Reply #4 on: March 08, 2004, 05:46:15 AM »
Do you have anything in particular where categories goes, or will it always say categories?

Offline sureshmulagala

  • Spaceship Captain
  • *****
  • Posts: 116
    • http://www.shopperbag.com
URL rewrite
« Reply #5 on: March 08, 2004, 05:50:30 AM »
no it only says categories....but there is no folder "categories"

this is the actual link

www.mydomain.com/jsp/mypage.jsp?id=123

i want to rewrite the url so the user wont see where the page is comming from....

to www.mydomain.com/categories/123.html

and it would be more nicer if it can be modified like this

www.mydomain.com/categories/category123.html

if you can help me achieve this, i will have to modify other pages on the same lines...

Regards

 :thumb:
Bid, Buy or Sell for Free
www.shopperbag.com

Priest

  • Guest
URL rewrite
« Reply #6 on: March 08, 2004, 06:01:47 AM »
OK, try this and see if it works:

Code: [Select]
RewriteEngine on
RewriteRule ^([^/]+)/categories([^/]+)/category([0-9]+)\.html$ jsp/mypage.jsp?id=$1


Note: It is very very late here so I may be a little off  :D

Offline sureshmulagala

  • Spaceship Captain
  • *****
  • Posts: 116
    • http://www.shopperbag.com
URL rewrite
« Reply #7 on: March 08, 2004, 06:09:27 AM »
doesnt seem to work steven..... :|
Bid, Buy or Sell for Free
www.shopperbag.com

Priest

  • Guest
URL rewrite
« Reply #8 on: March 08, 2004, 06:15:18 AM »
ok, I'll try simplicity first and add-on from there (sorry my brain's about half dead right now)

Code: [Select]
RewriteEngine on
RewriteRule ^/categories/([^/]+)\.html$ jsp/mypage.jsp?id=$1


Tell me if this works and we'll go from there

Offline sureshmulagala

  • Spaceship Captain
  • *****
  • Posts: 116
    • http://www.shopperbag.com
URL rewrite
« Reply #9 on: March 08, 2004, 06:20:19 AM »
Bid, Buy or Sell for Free
www.shopperbag.com

Priest

  • Guest
URL rewrite
« Reply #10 on: March 08, 2004, 06:46:18 AM »
OK, kid tested, mother approved...this worked on my site
Code: [Select]
RewriteEngine On
RewriteRule ^category\/categories([^/]+)\.html$ jsp/mypage.jsp?id=$1


Note: you may need to put /jsp/mypage.jsp?id=$1 if it doesn't work the way I have it, try this way

Offline sureshmulagala

  • Spaceship Captain
  • *****
  • Posts: 116
    • http://www.shopperbag.com
URL rewrite
« Reply #11 on: March 08, 2004, 06:51:59 AM »
works great ! steven...your a star....

but i presume the dependent images/js/css and stuff have to be in a created "category" folder...am i right? cuz it cant find em....
Bid, Buy or Sell for Free
www.shopperbag.com

Priest

  • Guest
URL rewrite
« Reply #12 on: March 08, 2004, 06:54:15 AM »
you don't have to move them, just add a / before the images.  Instead of using relative URL's you'll need to use absolute URL's

eg.. folder called jsp and inside that folder is images

instead of a script in jsp calling images/image.jpg you would need to call /jsp/images/image.jpg

Offline sureshmulagala

  • Spaceship Captain
  • *****
  • Posts: 116
    • http://www.shopperbag.com
URL rewrite
« Reply #13 on: March 08, 2004, 06:56:18 AM »
great !!  :thumb:

sorry to have bothered ya much....
Bid, Buy or Sell for Free
www.shopperbag.com

Priest

  • Guest
URL rewrite
« Reply #14 on: March 08, 2004, 07:00:25 AM »
No worries at all, that's what I'm here for  :D

Glad we got you taken care of  :thumb: