Solved

Apache HttpServer redirection with mod_rewrite

Posted on 2006-10-20
6
277 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
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
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 …
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now