Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

RewriteMap appending %0d to end of url

6:37 pm on Nov 14, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:June 23, 2003
votes: 0

System: Running apache2.0.59 on a windows xp machine.

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:
RewriteEngine On
RewriteMap splitparms "prg:c:/perl/bin/perl.exe C:/htdocs/websitecreator/app/scripts/apachemod.pl"
RewriteRule ^\/(.*)\.html /none1.php?${splitparms:$1} [R]


(noticed the %0d on the end).

Anyone have any ideas as to how I can correct this?


I don't think it matters, but here is my perl script:

#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)

if ($firstToken == 1)
$outStr = "pn=".$parmPair;
$firstToken = 0;
@tokens = split(/-/, $parmPair);
if (@tokens == 2)
$outStr .= "&".$tokens[0]."=".$tokens[1];

print $outStr."\n";

6:34 am on Nov 15, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

You might want to check to see how your PERL installation has defined "\n", because it must be the script that is appending the %0d carriage return.

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]

Note also that I modified the code so that it does only an internal rewrite and not an external redirect; It is the usual case that Webmasters do no wish to 'expose' query-string URLs to search engines and visitors, but rather use the search-engine-friendly URLs on their pages, and convert to query strings with name-value pairs only *inside* the server. You may wish to use the [R,L] flag for testing, but not for deployment.

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.



Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members