This seems so simple, but I can’t figure it out… I would like all requests to be rewritten to index.php (which will interpret the request) apart from 404.html which should be rewritten directly to 404.php.
The following code does work at rewriting everything to index.php, but 404.php never gets triggered.
I have left line 3 commented because I don’t know what it does.
Options +FollowSymlinks
RewriteEngine on
#RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^404.html$ 404.php [L]
RewriteRule ^(.*)$ index.php [QSA]
As you can see, my needs are very simple, but so is my brain! Please help!
Thanks.
EDIT
This line works fine on its own:
RewriteRule ^404.html$ 404.php
but when the other RewriteRule is introduced, everything gets forced through index.php – even 404.html…… (I tried changing the order too).
This was driving me MAD! but I found the answer, for those who are getting confused like I was.
Look at line 4:
Taken from: easymodrewrite:
The [L] flag can have unexpected results if you are not clear on how the module behaves. Note that the following only applies when mod_rewrite is used in a .htaccess file. The [L] flag behaves exactly as expected when used in httpd.conf.
The L flag will tell Apache to stop processing the rewrite rules for that request. Now what is often unrealised is that it now makes a new request for the new, rewritten filename and begin processing the rewrite rules again.
Basically, you have to tell the second rule not to match existing files (404.php is a real file, not dynamic).
Hope this helps someone.