Please pardon me as I am pretty a new comer to using .htaccess, and am getting a couple of difficulties with it as being the setup I want is, despite being simple, apparently rare.

Essentially, I am focusing on another domain attempting to hide .php extensions from pages, but although also redirecting demands for nonexistent pages to some custom search page. The general preferred effect is:

realpage => realpage.php


falsepage => search.php?q=falsepage

To date, the code I've (see below) appears to use the second properly, but instead of coming back 'realpage.php' for '' it returns a 404 error.

I have found versions that also move realpage to 'search.php?q=missing' just in case that provides any suggestion what may be failing!

My .htaccess file right now:

   Options +FollowSymLinks
   Options +Indexes

   RewriteEngine On

   RewriteBase /

   RewriteRule ^([^\.]+)$ $1.php [L]

   RewriteCond %{SCRIPT_FILENAME} !-f
   RewriteRule ^(.*)\.php$ search.php?q=$1 [L]

Thank you for any assist you to can provide! It's greatly appreciated!

I believe for the first rule, you would like something like:

RewriteBase /
RewriteRule ^([^.]+)$ $1.php [L]

I went that with the rewrite rule tester, and it'll direct 'realpage' to 'realpage.php'. In the event that does not work, I recommend crippling your next rule, ensuring the first is effective, then adding the look for missing files in later.