Conflicting RewriteRule in .htaccess

Here is a excerpt from my .htaccess located in the public_html folder:


RewriteEngine On

#rewrite rule for redirection
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ redirection.php?REQUEST_URI=%{REQUEST_URI} [NC,QSA]

#custom error page
RewriteRule ^errorpage.htm$ errorpage.php [R=301,NC]

“Errorpage.htm” does not exist anymore. The rewriterule works if the following code is commented out:


RewriteRule ^(.+)$ redirection.php?REQUEST_URI=%{REQUEST_URI} [NC,QSA]

What I want is nonexisting files and directories to be redirected to “redirection.php” except if the file is “errorpage.htm”

What is the best way to do this?

Try the L flag. It should stop any subsequent rules if the line gives a match:

RewriteEngine On
#custom error page
RewriteRule ^errorpage.htm$ errorpage.php [R=301,NC,L]

#rewrite rule for redirection
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ redirection.php?REQUEST_URI=%{REQUEST_URI} [NC,QSA]

Alternatively you can simply set errorpage.htm to be parsed as PHP and rename errorpage.php to errorpage.htm.