Apache HttpServer redirection with mod_rewrite

bala555
bala555 used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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*

Author

Commented:
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.

Author

Commented:
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]

***********************************************************************************
HonorGodSoftware Engineer

Commented:
Post a "request for point refunds" to the Community Suport group
PAQed with points refunded (500)

Computer101
EE Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial