Note that there are some explanatory texts on larger screens.

plurals
  1. POmod_rewrite regex rule with encoded new lines (%0A)
    text
    copied!<p>I'm having some problems with a mod_rewrite rule not matching, when I think it should.</p> <p>The rule is as follows:</p> <pre><code>RewriteRule ^api/(.*)\.(json|xml|csv|txt|printr|basictxt)$ api/endpoint.php?api_request=$1&amp;api_response_type=$2 [QSA] </code></pre> <p>And an example url is:</p> <pre><code>http://ourdomain.tld/api/aaaaa/bbbb/cccc%0Adddd.json </code></pre> <p>This rule works fine as long as you don't have <code>$0A</code> in the url (as far as I can tell).</p> <p>I realise that <code>.</code> means anything other than a new line and have tried rules like the following to get around either new lines or percentage symbols as I'm not sure quite how it is formatted at the time that mod_rewrite sees it, but none have worked:</p> <pre><code>RewriteRule ^api/([.\s]*)\.(json|xml|csv|txt|printr|basictxt)$ api/endpoint.php?api_request=$1&amp;api_response_type=$2 [QSA] RewriteRule ^api/([.\%]*)\.(json|xml|csv|txt|printr|basictxt)$ api/endpoint.php?api_request=$1&amp;api_response_type=$2 [QSA] RewriteRule ^api/([.%]*)\.(json|xml|csv|txt|printr|basictxt)$ api/endpoint.php?api_request=$1&amp;api_response_type=$2 [QSA] </code></pre> <p>Strangely even the following fails on all urls, even those without <code>%</code> symbols:</p> <pre><code>RewriteRule ^api/([.]*)\.(json|xml|csv|txt|printr|basictxt)$ api/endpoint.php?api_request=$1&amp;api_response_type=$2 [QSA] </code></pre> <p>I'd be very grateful if someone could shed some light on this for me as I cannot really go changing how the API works (IE I cannot make it base64 encoded, etc) and need to get a value to it with a new line in it.</p> <p>I've tested it at <a href="http://htaccess.madewithlove.be/" rel="nofollow">http://htaccess.madewithlove.be/</a> and their tool thinks it should work!</p> <p><strong>EDIT:</strong></p> <p><strong>We had a solution for the URL above but it didn't work with an example like:</strong></p> <pre><code>/api/something/sent+40.06K+bytes++received+7.83M+bytes++542.70K+bytes%2Fsec%0Atotal+size+is+19.83G++speedup+is+2520.16+%28Completed+in+14+seconds%29.json </code></pre> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload