Forum Moderators: phranque
We have an internal apache server which just redirects some virtual hosts.
Now I am told that I will be getting requests of the nature:
http://server1/amy/bob/jimmy/1234567890/connie
where the bold numbers represent a unix timestamp..
I need to redirect this to:
http://server2/bob/amy/connie/MMDDYY/jimmy
Where the MMDDYY is the unix time stamp converted to a standard date format. Also notice other portions of the URL are rearranged.
I have no idea where to start... can you guys give me a general idea what I need to use to accomplish this?
Please... point me in the right direction!
Thanks,
Jay
[edited by: jdMorgan at 9:40 pm (utc) on Sep. 10, 2009]
[edit reason] de-linked [/edit]
So, if you really want an external redirect (as opposed to an internal rewrite), I would suggest using mod_rewrite to internally rewrite all requests matching your URL "template" to a small PERL script which can do the time-format conversion and then send a redirect response to the client. This script would then execute in the content-handling phase of the API (mentioned only to contrast with the following).
If you do need a purely-internal-rewrite solution and have server config file access, look into using mod_rewrite's RewriteMap feature to call a PERL script in the URL-to-filename phase of the API, returning a converted-format internal path.
I'm being specific about internal rewrites and external redirects. If the difference is not crystal-clear, do not proceed until it is. A search of WebmasterWorld on "difference between rewrite redirect" may prove useful.
Jim
[edited by: jdMorgan at 4:26 pm (utc) on Sep. 11, 2009]
Using a perl script to generate the redirect URL sounds ideal. Can you point me in the right direction? A link or search keywords like you provided before would be awesome.
Thanks so much for your help, it has already been very valuable.
[use] mod_rewrite to internally rewrite all requests matching your URL "template" to a small PERL script which can do the time-format conversion and [this script can] then send a redirect response to the client.
In this case (generating an external redirect as opposed to an internal rewrite), you could also use PHP if you are more comfortable with that scripting language. Both PERL and PHP have the functions needed to do time-format-conversion and to output the server status response (301-Moved Permanently) code and Location headers.
Jim
The solution for me was to setup a virtual host which executed a perl script regardless of the path in the request to that host.
Your httpd.conf would have a section like:
<VirtualHost *:80>
ServerName yourhost.domain.com
ScriptAliasMatch ^/.* /path/to/script.pl
</VirtualHost>
Which will take any http:80 request to yourhost.domain.com starting with a '/' and execute script.pl
From there, the you can access all the environment variables inside the perl script. The following script will just print all the variables.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
foreach $key (keys %ENV) {
print "$key --> $ENV{$key}<br>";
}
From there, the responsibility is on the script to do whatever.
Thanks to everyone on here who chimed in and helped!
And having made that simplification, it then becomes obvious that since you want to match anything starting with a slash -- that is, any URL-path, the directive
ScriptAlias / /path/to/script.pl If you're on Apache 2.x, see also the "AcceptPathInfo" directive, which might come in handy for passing the URL-path into your script for easy retrieval as PATH_INFO
Jim