Note that there are some explanatory texts on larger screens.

plurals
  1. POMod Rewrite Regex - Multiple Negative Lookaheads
    primarykey
    data
    text
    <p>I currently have the working Mod Rewrite Regex:</p> <pre><code>RewriteEngine On RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*/)?((?:cmd)[^/]*)/((?!(?:cmd)[.+]*)(.+)) $1?$2=$3&amp;%1 [L] </code></pre> <p>That regex takes the following URL and transforms it into the URL immediately below:</p> <p><code>www.site.com/cmd1/param/cmd2/param2/stillparam2</code> and turn it into <code>www.site.com/index.php?cmd1=param&amp;cmd2=param2/stillparam2</code></p> <p>That works fine, but I would also like to create another negative lookahead assertion to ensure that a URL block - ie a <code>/texthere/</code> param - doesn't include an underscore. An invalid string might look like: <code>www.test.com/cmd/thing/getparam_valuehere</code>; the regex should parse the <code>cmd/thing</code> as a key and value pair and ignore the rest of the string. I would then also write another RewriteRule to have the block of the URL with the underscore in it added as another URL parameter. The following URL translation would occur:</p> <pre><code>www.test.com/cmd/param1/cmd2/directory/param2/sortorder_5 www.test.com?cmd=param1&amp;cmd2=directory/param2&amp;sortorder=5 </code></pre> <p>Please let me know if I have not been clear enough. Any help would be great.</p> <p>NB: I have tried using a negative lookahead nested inside the one already present - <code>(?!(?!))</code> - and have tried using an <code>|</code> on two negative lookaheads, but neither solutions worked. I thought that perhaps something else was more fundamentally wrong?</p> <p>Thanks all.</p> <p><strong>Edit:</strong> I have also tried the following - which I really thought would work (but obviously, didn't!)</p> <pre><code>RewriteRule ^(.*/)?((?:cmd)[^/]*)/((?!(?:cmd)[.+]*)(?![.+]*(?:_)[.+]*)(.+)) $1?$2=$3&amp;%1 [L] </code></pre> <p>That does the following:</p> <p><code>www.test.com/cmd/param1/sortorder_1/</code> translates to <code>www.test.com?cmd=param1/sortorder_1/</code></p> <p>When it should instead become: <code>www.test.com?cmd=param1&amp;sortorder=2/</code>. The rule to translate <code>/sortorder_2/</code> into<code>&amp;sortorder=2</code> has not yet been created, but you can hopefully see what I mean).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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