I have other scripts on the site but only want to rewrite for this particular script.
Could you tell me whether this is possible and want I need to enter into the server config file. I believe that rewriting the url is possible with an apache mod but I'm not that knowledgeable about server issues. Any help most appreciated.
This Introduction to mod_rewrite [webmasterworld.com] may be useful to you. However, why would you want to rewrite a long URL to a short one? Bearing in mind that the rewrite acts between the browser'r request and the server returning a file (or running a script), the more usual case is to rewrite a short URL to a long one. In this way, the user-supplied URL or on-page spiderable link is short, and is rewritten on request for use in accessing your page or script.
You can do it either way, just trying to clarify the goal here.
You are probably trying to make a virtual page look like a physical page? But wouldn't this cause some problems if the user bookmarks that final url? Or is this for like a search engine that finds a page listing in a database and then you want to return the real page directly without a click?
I'd like to do something similar when people come into a site without the framed menu, and then I route them into the menu with the current page (leaves a messy URL). I guess I will have to pick up the mod_rewrite manual myself. -aV-
With mod_rewrite you can do this by placing the following in an .htaccess or the httpd.conf file:
# To make it so that users can type in 319016.htm and the # server returns script.pl?action=form&fid=319016 you can # do this:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule "^/([0-9]+)\.htm$" [domain.com...] [P] </IfModule>
# Which basically says to remember the ID number (in $1) # and retrieve the other URL instead. The [P] at the end # says to do this all in proxy mode; without it Apache # would redirect the browser to the other URL.
# To go the other way -- users have to type in the long # version and the server retrieves the short URL (?!), you # could do this:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule "script\.pl\?.*fid=([0-9]+)" [domain.com...] [P] </IfModule>
The mod_proxy module is required if you want to use this proxying feature. Otherwise the browser will get redirected to the new URL.
The [P] flag is not required to prevent the server from doing an external redirect. An external self redirect is only done when you explicitly use the [R] flag. Otherwise the server will just return the resource pointed to by the rewritten URI.