Lunarpages Web Hosting Forum

Scripting Languages Hosting Help => C++ / PERL / CGI Support => Topic started by: sureshmulagala on March 08, 2004, 03:34:33 AM

Title: URL rewrite
Post by: sureshmulagala 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....
Title: URL rewrite
Post by: Priest on March 08, 2004, 03:46:10 AM
This out these related forum threads:

http://www.lunarforums.com/forum/viewtopic.php?t=9225&highlight=modrewrite
http://www.lunarforums.com/forum/viewtopic.php?t=12040&highlight=modrewrite
Title: URL rewrite
Post by: sureshmulagala on March 08, 2004, 05:12:09 AM
thanks steve...helped a lot....
Title: URL rewrite
Post by: sureshmulagala 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?
Title: URL rewrite
Post by: Priest on March 08, 2004, 05:46:15 AM
Do you have anything in particular where categories goes, or will it always say categories?
Title: URL rewrite
Post by: sureshmulagala 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:
Title: URL rewrite
Post by: Priest 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
Title: URL rewrite
Post by: sureshmulagala on March 08, 2004, 06:09:27 AM
doesnt seem to work steven..... :|
Title: URL rewrite
Post by: Priest 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
Title: URL rewrite
Post by: sureshmulagala on March 08, 2004, 06:20:19 AM
i tried

http://mydomain.com/categories/3.html

didnt work  :-?
Title: URL rewrite
Post by: Priest 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
Title: URL rewrite
Post by: sureshmulagala 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....
Title: URL rewrite
Post by: Priest 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
Title: URL rewrite
Post by: sureshmulagala on March 08, 2004, 06:56:18 AM
great !!  :thumb:

sorry to have bothered ya much....
Title: URL rewrite
Post by: Priest 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:
Title: URL rewrite
Post by: sureshmulagala on March 08, 2004, 07:05:29 AM
steve..would u be able to take one more question relating to the above? hope im not asking too much.... :wink:
Title: URL rewrite
Post by: Priest on March 08, 2004, 07:12:35 AM
no, what's up?
Title: URL rewrite
Post by: sureshmulagala on March 08, 2004, 07:22:17 AM
i have this following hirearchy

im having a wee bit of trouble, cuz im on windows and its different when it goes off on live on unix...

i cant even test it with .htaccess

on my local i have

c:\resin\doc\jsp          <--jsps go in here
c:\resin\doc\jsp\pics     <-- images go in here
c:\resin\doc\css          <-- css go in here
c:\resin\doc\js           <-- js go in here
c:\resin\doc\html         <--html go in here

on the live, i have something like

public_html\jsp          <--jsps go in here
public_html\jsp\pics     <-- images go in here
public_html\css          <-- css go in here
public_html\js           <-- js go in here
public_html\html         <--html go in here


so normally, the live would point like this:

http://mydomain.com/jsp/mainpage.jsp

and navigate to different subpages as:

http://mydomain.com/jsp/subpage.jsp?id=xxx

since we've masked the url to show something like

http://mydomain.com/categories/category23.html

any links resulting in this page would default to

http://mydomain.com/categories/xxxxx.html instead of looking to the root...

i have my "pics" folder in the "jsp" folder so used the images like pics/image.gif

now it wants all the files to be in categories folder....i dont know if its something to do
with the windows or its different on unix...since the root is defaulted to
"http://mydomain.com/categories"....do i have to remap all the paths in all the jsp files?

im prepared to bite the bullet...but just wanted to know before i start changing starting from page 1 to page 100...if youve got ideas, it might save me 10 man days....  :roll:

since all the jsps are in the jsp folder, all the links in the jsp look into the local folder, so i had to just give the link as <a href="page.jsp">go to page</a> , so obviously in this situations its lookign for /categories/page.jsp which its failing on.....
Title: URL rewrite
Post by: Priest on March 08, 2004, 07:27:59 AM
Really the only idea I have since the URL has been re-written is to change pics/image.gif to /jsp/pics/image.gif, using the absolute value instead of a relative value.

Course I've been awake for about 36 hours now and am kinda delirious, some other perl guru might be able to come in and tell you the easy way to do it, that's the only advice I have for ya though  :(
Title: URL rewrite
Post by: sureshmulagala on March 08, 2004, 07:34:30 AM
no problems....u get some sleep now.....laterz....

thanks and thanks a lot...i greatly appreciate your help
Title: URL rewrite
Post by: Ripta on March 08, 2004, 06:47:56 PM
I didn't quite follow this from the beginning, but if all images you're using are under the /jsp/pics, you could add another line in the htaccess:

Code: [Select]

RewriteRule ^categories\/(.+)\.gif$ /jsp/$1


which would turn requests for /categories/pics/image.gif into /jsp/pics/image.gif. :thumb: