homepage Welcome to WebmasterWorld Guest from 54.242.200.172
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
RewriteMap appending %0d to end of url
jchance




msg:3156478
 6:37 pm on Nov 14, 2006 (gmt 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:
---------<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>--------------

 

jdMorgan




msg:3156964
 6:34 am on Nov 15, 2006 (gmt 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.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved