Forum Moderators: phranque
Basically I want to take an address like this:
catalog.asp?N=36+2&Ne=1
And turn it into
36X2-1.asp
I'm grabbing the N value and the NE value, separating them by dashes, replacing the + with an X and boom.
That's what I want to do - changing the plus on the coding side is off limits unfortunately... I have to figure it out rewrite wise so my hands are a little tied.
For more information, see our forum charter [webmasterworld.com].
Thanks,
Jim
[edited by: jdMorgan at 5:51 pm (utc) on Feb. 28, 2008]
# Rewrite catalog.asp?N=<a>+<b>&Ne=<c> to /aXb-c.asp
RewriteCond %{QUERY_STRING} ^N=([^+]+)\+([^&]+)&Ne=([^&]+)
RewriteRule ^catalog\.asp$ /%1X%2-%3.asp [L]
Mod_rewrite is a "input" function, not an "output" function. Mod_rewrite operates on URLs when requested from your server, either externally redirecting them to a different URL, or "mapping" them to a different internal server filepath than that to which they would normally resolve.
Mod_rewrite has no effect on the content of pages returned in response to those requests. As such, I suspect that either the following code snippet is what you need, or that mod_rewrite cannot solve your problem as-stated. Crucial to understanding this is that the URLs which appear on your pages and are visible to client browsers (and search engine robots) are the "real" URLs; Their presence on your pages defines them as real URLs. If you want to change those URLs, then you must change the script that produces the pages -- Or "wrap" that script inside another one that parses the output from the inner script and modifies that output (this can be horribly inefficient).
If, in contrast to the title of this thread and the discussion above, the "real" URL that appears on your pages is "36X2-1.asp" and you want a request for that URL delivered to the script file "/catalog.asp" with name/value pairs of "N=36+2&Ne=1", then this code does so:
# Rewrite <a>X<b>-<c>.asp to catalog.asp?N=<a>+<b>&Ne=<c>
RewriteRule ^([^X]+X([^-]+)-([^.]+)\.asp$ /catalog.asp?N=$1+$2&Ne=$3 [L]
The resources cited in our forum charter and the contents of our forum Library may be quite helpful in understanding this.
Jim