Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache rewrite rule similar to Nginx try_files

Tags:

apache

In Nginx I played around with try_files which basically took any request for a file on the domain and passed it through a custom php script called file_parse.php. In Nginx it looked like this: try_files $url /file_parse.php

If the file did exist in the document root then it did not use try_files. This rule in Nginx doesn't redirect the user, for example if a user types in http://www.domain.com/123456.html that address shows in their browser but file_parse.php takes 123456.html and echo's out html code based on the number (123456). If file_parse.php doesn't have anything to echo out then file_parse.php sets a 404 header for the client.

Does something like this exist in Apache?

like image 562
Blake Avatar asked Oct 08 '22 11:10

Blake


1 Answers

Found an answer, seems to work, no errors in error.log:

<Directory /this/is/the/directory/>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . file_parse.php [L]
</Directory>
like image 157
Blake Avatar answered Oct 13 '22 01:10

Blake