Forum Moderators: phranque
I'm attempting to use RewriteMap to do some complex url rewriting. The problem I'm running into is that for some reason my urls end up with a %0d appended to the end. I have searched the net for solutions and have found several people with the same problem but have not found a solution.
I believe this problem is specific to apache on windows and specifically deals with the difference between a windows newline and a unix newline, but can't guarantee that.
Here is my modrewrite directives in my httpd.conf:
---------<snip>--------------
RewriteEngine On
RewriteMap splitparms "prg:c:/perl/bin/perl.exe C:/htdocs/websitecreator/app/scripts/apachemod.pl"
RewriteRule ^\/(.*)\.html /none1.php?${splitparms:$1} [R]
---------<snip>--------------
Example:
[mywebsite.com...]
Produces:
[mywebsite.com...]
(noticed the %0d on the end).
Anyone have any ideas as to how I can correct this?
Thanks,
Jason
I don't think it matters, but here is my perl script:
---------<snip>--------------
#!/usr/bin/perl
#What I want to achieve here:
#$STDIN = "testhtml__pl-32__jg-55__psd-92";
#$RETURN= "pn=testhtml&pl=32&jg=55&psd=92";
$¦ = 1; # Turn off buffering
while (<STDIN>)
{
@parmTokens = split(/__/,$_);
$firstToken = 1;
$outStr = "";
foreach $parmPair (@parmTokens)
{
chomp($parmPair);
if ($firstToken == 1)
{
$outStr = "pn=".$parmPair;
$firstToken = 0;
}
else
{
@tokens = split(/-/, $parmPair);
if (@tokens == 2)
{
$outStr .= "&".$tokens[0]."=".$tokens[1];
}
}
}
print $outStr."\n";
}
---------<snip>--------------
However, despite the fact that examples are mutually-inconsistent, it seems to me that the RewriteMap-with-script approach is unnecessary, and a waste of processing resources.
Based on what I see, the RewriteMap and script could be replaced by a simple RewriteRule:
RewriteRule ^/([^_]+)__([^-]+)-([^_]+)__([^-]+)-([^_.]+)\.html$ /none1.php?pn=$1&$2=$3&$4=$5 [L]
The rule above assumes five parameters: A page name, plus two name-value pairs. If you may have more or fewer name-value pairs, then this rule would need to be accompanied by rules that can 'split' more or fewer name-value pairs.
"[^_]+" means "Match one or more characters not equal to an underscore," or equivalently "Match all characters up to the next underscore."
We then match two underscores in a row -- that's what it looks like you've got in your "input" URL.
Then we have "[^-]+" meaning, "Match one or more characters not equal to a hyphen," or equivalently, "Match all characters up to the next hyphen."
Then we match a hyphen.
Next we repeat the underscore-matching, then another hyphen match.
Finally, we have "[^_.]+" which means, "Match one or more characters not equal to a underscore or a period," or equivalently, "Match all characters up to the next underscore or period." This last bit --including both the underscore and the period-- is critical to preventing a match on a requested URL that does not match the template in your examples -- e.g. to reject URLs with more parameters.
Jim