in reply to redirecting, html forms, mechanize
Just out of curiosity - why aren't you using mod_rewrite for this? If you are using an Apache server (maybe you are not?), you can handle simple static redirections like the above directly in the server. Perl scripts are really only needed if you are dynamically selecting the redirection location or munging the post parameters before you redirect.
Best, beth
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: redirecting, html forms, mechanize
by RobertCraven (Sexton) on Jun 28, 2009 at 01:02 UTC | |
thanks for your answer. I am not really a web-programmer or webmaster. I am just at the beginning to learn all the things Apache can do. I read a bit about the mod_rewrite, using it seems like a good idea. This task has been assigned pretty much last minute to me, is there a chance that you could give me some hints how to transfer files using mod_rewrite? Many thanks, Thomas | [reply] |
by ELISHEVA (Prior) on Jun 28, 2009 at 04:53 UTC | |
Unfortunately, I can't give more than general help and learning tips. I'm only a casual user of mod_rewrite and don't have an experimental Apache server handy. On one foot, mod_rewrite lets you use Perl compatible regular expressions to convert a part of a URL you don't like to one you do like. The phrase "Perl compatible" should be taken with a small grain of salt - usually it means some subset of full-blown Perl regexes. I've never really done much more than simple rewrites, so I don't really know how full the emulation is (perhaps some other monk does?). The hardest part of mod_rewrite is learning its syntax for selecting URLs to be rewritten. In my experience, when mod_rewrite "doesn't work", it is usually a screw up with the selection process: thinking selection criteria are being or'd when they are really being and'd; regexes that don't do what you think they do; accidentally chaining together rules, and so on. Basically, you define a set of rules for selecting a URL using a series of RewriteCond statements. Each of these has three parts: the word "RewriteCond", a variable representing the thing you want to match (e.g. %{REMOTE_HOST}), and a regex to compare to it. These are the equivalent of $servervar =~ /.../ expressions in Perl. A series of these RewriteCond statements is normally and'd together but you can "or" them, by adding [OR] at the end of each RewriteCond statement. At the end of all of the RewriteCond statements, is a RewriteRule statement. This contains the URL transformation and has the format: RewriteRule regex-matching-what-you-want-to-get-rid-of text-you-actually-want.You can think of it as a fancy version of Perl substitution: s/regex-matching-what-you-want-to-get-rid-of/text-you-actually-want. So your redirection to MolSurfer might look something like this:
The things in square brackets at the end are instructions to the server. [OR] was already discussed above. L means "the end". If it is missing, and there is another set of RewriteCond/RewriteRule statements after it, Apache chains them, just as if you had successive $foo =~ s/blah/blech/ statements in a Perl script. [NC] means ignore case. See the documentation for other codes. The official documentation is very far from a tutorial, so here are some articles with examples. These should get you started. After reading them, you may want to go back to the mod_rewrite reference page and see if anything there starts making more sense.
You might also try searching the net for Apache forums - you are likely to get more detailed help there. There is also a way you can insert a Perl script to do the URL conversion if you need to get a bit fancier with the conversion or use something like a lookup table stored in a database, but that is a lot more complex than you probabably need right now. If you are interested in it later on, scan the main mod_rewrite documentation page for the word "Perl". They have a short sample script. Best, beth | [reply] [d/l] [select] |
by RobertCraven (Sexton) on Jun 28, 2009 at 23:07 UTC | |
thank you so much for your time and effort. Thank you!
| [reply] [d/l] |