 |
|
 |
|
|
 |
.htaccess redirect Perl/CGI -> PHP |
 |
 |
|
|
12-22-04 10:51 PM
I'm relatively new to .htaccess modifications so apologies if this is a
basic question.
I have a file at www.example.com/file.cgi (Perl Script) that I want to
redirect to www.example.com/file.php. I do this in the .htaccess:
Redirect Permanent /file.cgi http://www.example.com/file.php
This works great with one huge exception. That is, the variables that
were POSTed to the original CGI script were not passed on to the PHP
script.
Using the above example, is there a simple way via .htaccess to
configure the server to redirect to my php script and pass on the POST
variables too? Thanks!
- JR
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: .htaccess redirect Perl/CGI -> PHP |
 |
 |
|
|
12-22-04 10:51 PM
On Wed, 22 Dec 2004 russet32@hotmail.com wrote:
> I have a file at www.example.com/file.cgi (Perl Script) that I want
> to redirect to www.example.com/file.php.
Why do you want to redirect? Once we know the answer to that, we may
be better able to advise.
> I do this in the .htaccess:
>
> Redirect Permanent /file.cgi http://www.example.com/file.php
If I couldn't persuade those responsible for the web page(s)
to change their links, I think I'd be inclined to do something
like this instead:
<Files file.cgi>
AddType application/x-httpd-php .cgi
</Files>
i.e to define this particular file as a PHP.
(Or use AddHandler if you're happier with that.)
(However, t [This might be problematical if it's in a subdirectory
that was configured by means of ScriptAlias .. - but from your
example, I don't think you could be doing that anyway]
The user (client) has no real business concerning themselves whether
the resource is a CGI, PHP, ASP or whatever. The filename extension
is a purely private matter between you and your web server - what it
means is really up to you to decide, and configure. For example, I
have hierarchies in which the .html extension is defined to be an SSI.
> Using the above example, is there a simple way via .htaccess to
> configure the server to redirect to my php script and pass on the POST
> variables too?
In practice, the answer is "no", I'm afraid. Some details at:
http://ppewww.ph.gla.ac.uk/~flavell...t-redirect.html
good luck
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: .htaccess redirect Perl/CGI -> PHP |
 |
 |
|
|
12-22-04 10:51 PM
Alan J. Flavell wrote:
> Why do you want to redirect? Once we know the answer to that, we may
> be better able to advise.
Redirect may not be the right term to use. I'm not sure. Anyway, the
reason for my desired redirect is that I have external sites POSTing
information to my .cgi PERL script. For maintenance preference, I want
it port my code to a php script. No changes done on the client side,
only on my server side. You gave me a solution to my "simple" example.
It is a little more complex in this regard. The reality of the
situation is that I have four different .CGI scripts. For example:
/script1.cgi
/script2.cgi
/script3.cgi
/script4.cgi
They are very simple scripts that process the POSTed data and return
data back to the originator. To make things more manageable, and for
my perference of making them PHP, I would like to have all four of
these scripts handled by **one** php script (with no changes done on
the client side). For example, this partially accomplishes this task
in a .htaccess file
Redirect /script1.cgi http://www.example.com/script.php?type=1
Redirect /script2.cgi http://www.example.com/script.php?type=2
Redirect /script3.cgi http://www.example.com/script.php?type=3
Redirect /script4.cgi http://www.example.com/script.php?type=4
By doing this, my one script.php file is able to handle all originating
CGI requests and to know which of the four scripts it should handle.
Again, my problem comes from the fact that the POSTed data that was
sent to original .CGI script is not passed along with the redirection.
In studying .htaccess directives, it seems like there is a way to do
this but, given my inexperience with it, I haven't quite nailed it down
yet. If you have any thoughts on how to accomplish this without any
client change, I'd certainly appreciate it.
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: .htaccess redirect Perl/CGI -> PHP |
 |
 |
|
|
12-22-04 10:51 PM
On Wed, 22 Dec 2004, russet32@hotmail.com wrote:
> Redirect /script1.cgi http://www.example.com/script.php?type=1
> Redirect /script2.cgi http://www.example.com/script.php?type=2
I see what you're getting at. I'm not over-enthusiastic about
mixing the use of query strings with POSTed data, although the author
of the respected CGI.pm PERL module seems quite happy to support it,
so if he says it's OK, I suppose I shouldn't really argue.
> By doing this, my one script.php file is able to handle all originating
> CGI requests and to know which of the four scripts it should handle.
But there's really no need for an explicit redirection - and, as my
web page showed, browser support for redirecting POST transactions is
miserable, it really isn't going to work in a WWW context.
If the web pages that invoke this lot aren't going to change, then you
can keep the changes all internal to the server, as far as I can see,
and the client has no need to know anything at all about it.
> Again, my problem comes from the fact that the POSTed data that was
> sent to original .CGI script is not passed along with the
> redirection.
Quite. Again, the reports in my web page should be enough to frighten
you off that approach.
> If you have any thoughts on how to accomplish this without any
> client change, I'd certainly appreciate it.
Well, mod_rewrite can surely do what you want (and without any
visible external redirection), assuming that the server has it
available.
It's fairly heavy stuff, because it can do so many different things.
What I think you are looking for (off the top of my head) is a
passthrough rule, i.e one with the [PT] flag on it. You certainly do
*not* want a redirection [R] flag.
But a simpler approach - which I think would work - not tested! -
would be to symlink your various CGI file names all to the real name
of your php script, and then to query within the script to find out
which file name was used for invoking it, and thus deduce which action
it should perform.
ln -s foo.php one.cgi
ln -s foo.php two.cgi
and so on. You still need an AddType or AddHandler to tell the
server that these *.cgi names need to be serviced as php scripts.
And then, even though it'll invoke foo.php, the REQUEST_URI will show
that it was really invoked as two.cgi or whatever, and your PHP
script can proceed accordingly. Any help?
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: .htaccess redirect Perl/CGI -> PHP |
 |
 |
|
|
12-22-04 10:51 PM
On 22 Dec 2004, russet32@hotmail.com <russet32@hotmail.com> wrote:
> I'm relatively new to .htaccess modifications so apologies if this is a
> basic question.
>
> I have a file at www.example.com/file.cgi (Perl Script) that I want to
> redirect to www.example.com/file.php. I do this in the .htaccess:
>
> Redirect Permanent /file.cgi http://www.example.com/file.php
>
> This works great with one huge exception. That is, the variables that
> were POSTed to the original CGI script were not passed on to the PHP
> script.
>
> Using the above example, is there a simple way via .htaccess to
> configure the server to redirect to my php script and pass on the POST
> variables too? Thanks!
Best option is to correct your form, since whether a browser passes POST
variables through a redirect depends upon the browser and may depend upon
security settings. I believe Randal Schwartz of PERL fame explains that
somewhere on http://www.stonehenge.com/merlyn/WebTechniques/ but I cannot
find the specific column at this moment.
Less simple would probably be mod_rewrite to locally redirect the request
(instead of through the browser).
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: .htaccess redirect Perl/CGI -> PHP |
 |
 |
|
|
12-23-04 07:46 AM
Alan and David,
Thanks for your help. This is what I will do in the .htaccess:
RewriteEngine on
RewriteRule ^script1.cgi script.php
RewriteRule ^script2.cgi script.php
RewriteRule ^script3.cgi script.php
RewriteRule ^script4.cgi script.php
I have tested it with only the script1.cgi rewrite for starters and it
works fine. Then, in my php script I parse out $_SERVER['REQUEST_URI']
to determine which .CGI file the request was originally intended for.
I do not expect any problems when I have all four rewrite rules and
then I will have one php file servicing four different .CGI requests
(which was my original goal, as well as moving PHP).
There may be a better way. I'll be reading up on mod_rewrite to make
sure that I fully understand this before going live with any changes.
Thanks!
[ Post a follow-up to this message ]
|
|
|
 |
|
|
|
|
Sponsored Links |
 |
 |
|
|
 |
All times are GMT. The time now is 01:09 PM. |
 |
|
|
 |
|
 |
|
|
 |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
|
|
|
|
Medical and Health forum | Computer Games Reviews | Graphics design forum
|
 |
|
 |
|