Attempting to replace all cases of Content management systems_ with X. Only handled to obtain infinite loops to date.

Input: /mydir/?CMS_q=1&CMS_g=3 ...
Output: ?Xq=1&Xg=3 ...

.htaccess:

RewriteEngine On
RewriteRule ^/?mydir/(.+) $1                      [R]
RewriteRule ^(.*?)CMS_(.*?CMS_.*)$ $1X$2            [N,R]
RewriteRule ^(.*?)CMS_(.*)$ $1X$2               [L,R]

I'd a functional script a couple of years back and dropped it. I do not remember ever doing the "replace 1 at any given time until 1 remainsInch business however i first viewed it recommended inside a similar question. Can't appear to have it working regardless.

You cannot match from the query string in RewriteRule, which only matches from the URI. You are able to take away the Content management systems_ in the query string by using this:

RewriteCond %{QUERY_STRING} (.*)CMS_(.*)
RewriteRule ^(.*)$ /$1?%1X%2

Permitting this to loop will replace the Content management systems_ with X, mod_rewrite continues to loop through this until you will find forget about Content management systems_ within the query string. This is when the 2nd rule is available in to experience:

RewriteCond %{QUERY_STRING} !CMS_
RewriteRule ^mydir/$ / [L,R]

First have to check to make certain you will find no Content management systems_ within the query string (otherwise the rule getting rid of the mydir in-front is going to be applied prematurely), then, take away the mydir in-front. Also remember the RewriteEngine On before all this.

These 2 rules can lead to a request http://yourdomain.com/mydir/?CMS_q=1&CMS_w=2&CMS_e=3&CMS_r=4 to become rerouted to http://yourdomain.com/?Xq=1&Xw=2&Xe=3&Xr=4