Solved

Apache HttpServer redirection with mod_rewrite

Posted on 2006-10-20
6
282 Views
Last Modified: 2010-04-16
Need help with Apache HTTP Server redirection.
I have a URL like this

 http://localhost.domain.com/vehicledirect/vehicle.jsp?direct=true

Now, I need to redirect the user to a URL like this.

 http://localhost.domain.com/dealerdirect/dealer.jsp?direct=true&vehicle=somevehicle

So, there are two changes to the new URL.
1.Update to request URI (replace vehicledirect/vehicle.jsp with dealerdirect/dealer.jsp)
 2.Add a new parameter to query string. (vehicle=somevehicle)

I need a Rewrite rule to perform this operation. I'm using apache httpd.conf file to set this.
Please help.
0
Comment
Question by:bala555
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:mploschiavo
ID: 17778448
what are you trying to do?  link to KBB or something like that?

you probably want to use some similiar syntax like:
from
http://httpd.apache.org/docs/2.0/mod/mod_alias.html

ScriptAlias Directive
Description: Maps a URL to a filesystem location and designates the target as a CGI script
Syntax: ScriptAlias URL-path file-path|directory-path
Context: server config, virtual host
Status: Base
Module: mod_alias

The ScriptAlias directive has the same behavior as the Alias directive, except that in addition it marks the target directory as containing CGI scripts that will be processed by mod_cgi's cgi-script handler. URLs with a case-sensitive (%-decoded) path beginning with URL-path will be mapped to scripts beginning with the second argument, which is a full pathname in the local filesystem.

Example:
ScriptAlias /cgi-bin/ /web/cgi-bin/

A request for http://myserver/cgi-bin/foo would cause the server to run the script /web/cgi-bin/foo. This configuration is essentially equivalent to:

Alias /cgi-bin/ /web/cgi-bin/
<Location /cgi-bin >

SetHandler cgi-script
Options +ExecCGI

</Location>
OR

RedirectMatch Directive
Description: Sends an external redirect based on a regular expression match of the current URL
Syntax: RedirectMatch [status] regex URL
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Status: Base
Module: mod_alias

This directive is equivalent to Redirect, but makes use of standard regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL-path, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename. For example, to redirect all GIF files to like-named JPEG files on another server, one might use:

RedirectMatch (.*)\.gif$ http://www.anotherserver.com$1.jpg 


============================

good luck....

matthew loschiavo
*advertising removed*
0
 

Author Comment

by:bala555
ID: 17778461
I have gone thru all those materials but could not understand much and here i'm. I really looking for a 'RewriteRule' using 'mod_rewrite' for this scenario.
0
 

Author Comment

by:bala555
ID: 17778762
never mind, i did a little more study and wrote a solution by myself.

Here is the working solution.
**********************************************************************************

RewriteMap text int:unescape
RewriteCond %{QUERY_STRING} ^([a-z]+)=([a-z]+)
RewriteRule ^/vehicledirect/vehicle.jsp$ /${text:dealerdirect/dealer.jsp?%1=%2&vehicle=somevehicle} [L,R]

***********************************************************************************
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17780059
Post a "request for point refunds" to the Community Suport group
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 17962841
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question