.htaccess RewriteRule, check if RewriteRule target exists

Giganews Newsgroups
Subject: .htaccess RewriteRule, check if RewriteRule target exists
Posted by:  jwcarlton (jwcarlt…@gmail.com)
Date: Mon, 4 Oct 2010

I have another question regarding RewriteRule, and I'm hoping you guys
can help me out.

Here's what I have now:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index\.php !-f
RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*)/(.*)/(.*) /$2/$3?ef=$1&${REQUEST_URI} [QSA,NC,L]

This effectively redirects something like "/business/faq/?answer=12"
to "/faq/index.php?ef=business&answer=12", which is exactly what I
want.

But now, I want to add in another check to make sure that /$2/$3
exists; else, go to a default "/info/index.php?ef=$1&var2=$2&var3=$3".

How do I check if /$2/$3 exists, and if not, RewriteRule to another
page?

Replies