apacheRewriteRule / RewriteCond help when two "keywords" show in the one query string

Currently I have this in my .htaccess file:

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /forum/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpeg|jpg|gif|png)$ /forum/public/404.php [NC,L]

RewriteCond %{QUERY_STRING} (?:^|&)app=core(?:&|$) [NC]
RewriteCond %{QUERY_STRING} (?:^|&)section=register(?:&|$) [NC]
RewriteRule ^index\.php$ http://www.mysite.com/register.php? [NC,L,R=302]

RewriteCond %{QUERY_STRING} (?:^|&)app=core(?:&|$) [NC]
RewriteCond %{QUERY_STRING} (?:^|&)section=login(?:&|$) [NC]
RewriteRule ^index\.php$ http://www.mysite.com/login.php? [NC,L,R=302]

RewriteCond %{QUERY_STRING} (?:^|&)app=core(?:&|$) [NC]
RewriteCond %{QUERY_STRING} (?:^|&)section=lostpass(?:&|$) [NC]
RewriteRule ^index\.php$ http://www.mysite.com/retrieve_password.php? [NC,L,R=302]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forum/index.php [L]
</IfModule>

The one I need help with is this one:

RewriteCond %{QUERY_STRING} (?:^|&)app=core(?:&|$) [NC]
RewriteCond %{QUERY_STRING} (?:^|&)section=login(?:&|$) [NC]
RewriteRule ^index\.php$ http://www.mysite.com/login.php? [NC,L,R=302]

Currently this will redirect something like:

http://www.mysite.com/forum/index.php?app=core&module=global&section=login

The &module=global isn't required so as I'm sure you can tell it only looks for the app & section parameters.

However the problem is, it also redirects the logout link I want to redirect somewhere else as it also contains app=core & &section=login.

Here is an example:

http://www.mysite.com/forum/index.php?app=coree&module=global&section=login&do=logout&k=xxxxxxxxxxxxxxxxxxx

So basically the login should still redirect as above unless it has &do=logout in the query string; in that case I want to redirect it somewhere else.

How can I go about doing this?

Change your rule to:

RewriteCond %{QUERY_STRING} (?:^|&)app=core(?:&|$) [NC]
RewriteCond %{QUERY_STRING} (?:^|&)section=login(?:&|$) [NC]
RewriteCond %{QUERY_STRING} !(?:^|&)do=logout(?:&|$) [NC]
RewriteRule ^index\.php$ http://www.mysite.com/login.php? [NC,L,R=302]

Here RewriteCond %{QUERY_STRING} !(?:^|&)do=logout(?:&|$) [NC] will skip redirect if &do=logout is present in the query string.

EDIT: As per comments:

RewriteCond %{QUERY_STRING} (?:^|&)app=core(?:&|$) [NC]
RewriteCond %{QUERY_STRING} (?:^|&)section=login(?:&|$) [NC]
RewriteCond %{QUERY_STRING} (?:^|&)do=logout(?:&|$) [NC]
RewriteRule ^index\.php$ http://www.mysite.com/logout.php? [NC,L,R=302]

Related Articles
You Might Also Like