David Heisnam
David Heisnam

Reputation: 2491

HTACCESS PUZZLE! Why does "?" work in one Rewrite statement and doesn't in another? See example

So, I've been working on htaccess since like yesterday. I have two Rewrite statements in my htaccess file.

RewriteRule ^.*wp-login\.php\?loggedout=true.*$ /not_found [R,L]

The above statement works. While

RewriteRule ^.*wp-login\.php\?action=login.*% /not_found [R,L]

...doesn't!

To make the second case work, I used the following statements.

RewriteCond %{QUERY_STRING} action=logout

RewriteRule ^wp-login\.php$ /not_found/? [R,L]

So, not using "?action=logout" in the RewriteRule in the second case seems to solve the problem.

Yes, the problem is solved, but I'd like to understand why. This is so puzzling.

Any help is appreciated. Thank you.

Upvotes: 2

Views: 63

Answers (1)

anubhava
anubhava

Reputation: 785186

Your earlier rules are incorrect because QUERY_STRING cannot be matched in RewriteRule. RewriteRule only match request uri without query string.

So correct rules are:

RewriteCond %{QUERY_STRING} (^|&)action=logout(&|$)
RewriteRule ^wp-login\.php$ /not_found/? [R,L]

OR this to include both query parameters:

RewriteCond %{QUERY_STRING} (^|&)action=(login|logout)(&|$)
RewriteRule ^wp-login\.php$ /not_found/? [R,L]

Upvotes: 2

Related Questions