File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes URL Rewriting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "URL Rewriting" Watch "URL Rewriting" New topic

URL Rewriting

Parth Bhagat

Joined: Mar 14, 2013
Posts: 7

Can any one explain the concept of URL Rewriting? I am having confusion with that.

Confusion is:
1.) URL Rewriting is used for Session tracking, by sending parameters/values to the URL as with get request.
2.) URL Rewriting is used for SEO, to make URL readable & easy to remember.

Can any one brief about the concept itself?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

URL Rewriting

[Asking smart questions] [About Bear] [Books by Bear]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
That Wikipedia article covers only half of it, namely the #2 of Parth's question. That's the part where the external URL that the user (or a search engine) sees is different from the internal URL that the web app actually handles.

The first part is about changing a URL that is generated in the web app *before* it is sent out. Thus the altered URL is the same externally and internally. The only difference is the addition of the session cookie, though, which the servlet container handles, and not the web app code.
Amit Ghorpade

Joined: Jun 06, 2007
Posts: 2851

Welcome to Javaranch Parth

URL rewriting is basically changing/ modifying the URL from what it should have been to something that either helps to maintain session (like when cookies are disabled) and other things like adding security, SEO, etc.
So lets say my original URL for a successful admin login page was I would rewrite it to
Now both the above URLs server the same page and purpose. The latter one adds up two query string params to avoid cookies but still have some sort of authentication data in the request.
You can try disabling cookies in your browser to check out the difference in the URLs for most sites that use this approach, you will likely notice the jsessionid being appended at the end of the URL when you disable cookies. Although not all sites work can work that way.

Hope this helps.

|Asking Good Questions|
Parth Bhagat

Joined: Mar 14, 2013
Posts: 7

Thank you all for your valuable reply.

Here is what I understood from these replies.
1.) For SEO purpose: It is done with the help of Rewrite Engine running on Web server.
2.) Session Tracking: In case when Browser Cookie is disable, using encodeURL method of HttpServletResponse instance session can be tracked for current transaction to the application.

Session tracking with URL Rewriting.

Please correct me if I am wrong at any point.

Thanks again for your responses.
I agree. Here's the link:
subject: URL Rewriting
It's not a secret anymore!