Forum Moderators: phranque

Message Too Old, No Replies

Looking for a universal rewrite

Dynamic to static pages in Apache

         

elguiri

5:20 pm on Jul 5, 2005 (gmt 0)

10+ Year Member Top Contributors Of The Month



Rewrite questions are among the most common in webmaster forums, and in trying to solve a specific problem I've searched through most of them.

However, I've been unable to find in forums something which I'm convinced exists. Most people ask specific questions and get a specific answer. I think however something more universal is in order, and although I'm sure someone has written it somewhere, I can't find it.

Last month, after a day searching around, I came up with a rule to insert in httpd.ini file on an IIS server that would write:

http://www.example.com/foo.asp?A=a&B=b&C=c

to

http://www.example.com/A/a/B/b/C/c/foo.asp

The great thing is that the rule works regardless of a) the number of parameters or b) the order in which they appear. I wrote it up [in my blog].

Now my question is what is the code that will work for 90% of people needing to rewrite dynamic URL's as static in the Apache world?

How do I write:

http://www.example.com/foo.php?A=a&B=b&C=c

to

http://www.example.com/A/a/B/b/C/c/foo.php

... regardless of the number of parameters or order in which they appear?

[edited by: jdMorgan at 5:15 pm (utc) on July 6, 2005]
[edit reason] Removed URL per Terms of Service. [/edit]

catch2948

3:26 pm on Jul 6, 2005 (gmt 0)

10+ Year Member



elguiri:

[Search for an article] entitled "not-so-simple rewriting" ... That should answer your question pretty well ...

[edited by: jdMorgan at 5:16 pm (utc) on July 6, 2005]
[edit reason] Removed URL per Terms Of Service. [/edit]

jdMorgan

5:23 pm on Jul 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Functions like this can be accomplished by using the [N] flag of RewriteRule to re-invoke a ruleset repeatedly until the rule pattern no longer matches. The problem with this approach is that it is highly-inefficient, especially when the rules are being processed in an .htaccess per-directory context, where the code is interpreted rather than being compiled (as it is in httpd.conf).

If you have access to httpd.conf, another option is to process the request using an external cgi script--something like PERL that has better multiple-search-and-replace capabilitied than mod_rewrite.

Finally, you could use mod_rewrite to pass *all* requests matching a very basic template to your script, and do the parameter extraction within the script itself.

Jim