RewriteRule with QueryString?

I need to redirect and use a portion of the query string and its driving me crazy.

Here is the url I want to rewrite:|7a8cfb75daa8ec0ecfbc2159.1-1540510346|CrKwz4iF0pTab4YlygeF2_4R29M&redirect=http%3A//

I need to take everything after undefinedindex.php and redirect that to /community.index.php so the redirect should go to:|7a8cfb75daa8ec0ecfbc2159.1-1540510346|CrKwz4iF0pTab4YlygeF2_4R29M&redirect=http%3A//

I’ve tried every variation of

RewriteRule ^undefinedindex.php(.*)$ /community/index.php [NC,L,R]

but nothing seems to work.

Any help is greatly appreciated!

Note: Query String

The Pattern will not be matched against the query string. Instead, you must use a RewriteCond with the %{QUERY_STRING} variable. You can, however, create URLs in the substitution string, containing a query string part. Simply use a question mark inside the substitution string, to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine a new query string with an old one, use the [QSA] flag.

Source: mod_rewrite - Apache HTTP Server


What hexburner quoted (albeit, quoting can seem like quoting Greek - to a non-Greek!). The important thing from that quote, though, is that you MUST examine a query string using a RewriteCond statement (the rest concerns generating the query string in the redirection).

More important to your case, though, is that you have not looked at the characters which are allowed in a URL (and WHERE). Sir Tim Berners-Lee has an even more geek-speak article on just this situation (Uniform Resource Identifiers (URI): Generic Syntax). Rather than make you go through all that, you simply cannot use a protocol:// in a query string (following the protocol/URI). The simple way around that is to assume the protocol AFTER you strip the value of redirect in the receiving script.

I have a lengthy mod_rewrite tutorial page linked in my signature which has been a help to members through the years.