EN
apache2 / .htaccess - run php script if file does not exist
9 points
In this short article we would like to show you how configure .htaccess
to execute some alernative script when file indicated in URL doesn't exist on apache2 server.
Quick solution (.htaccess
file):
xxxxxxxxxx
1
RewriteEngine on
2
RewriteCond %{REQUEST_FILENAME} !-f
3
RewriteRule ^.*$ /script.php [L]
Web site structure:
xxxxxxxxxx
1
/var/www/html
2
├── .htaccess
3
├── file1.txt
4
├── file2.txt
5
└── script.php
xxxxxxxxxx 1 RewriteEngine on 2 RewriteCond %{REQUEST_FILENAME} !-f 3 RewriteRule ^.*$ /script.php [L]
xxxxxxxxxx 1 file1.txt content ... 2 file1.txt content ... 3 file1.txt content ...
xxxxxxxxxx 1 file2.txt content ... 2 file2.txt content ... 3 file2.txt content ...
xxxxxxxxxx 1
2 3 echo "Script executed ..."; 4 5
|
Screenshots:



