Solved

Apache HttpServer redirection with mod_rewrite

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 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

20 Experts available now in Live!

Get 1:1 Help Now