Apache rewrite rule is similar to Nginx try_files

In Nginx, I played around with try_files which basically accepted 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 existed in the document root, it did not use try_files. This rule in Nginx does not redirect the user, for example if the user enters http://www.domain.com/123456.html which shows the address in their browser but file_parse.php takes 123456.html and outputs the html code based on the number (123456). If file_parse.php has nothing to respond to, then file_parse.php sets a 404 header for the client.

Does something like this exist in Apache?

+1


source to share


2 answers


Found the 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>

      

+3


source


Does something like this exist in Apache?



Have a look at the mod_rewrite RewriteMap directive , specifically the type of map prg

that allows you to run a script and pass request information.

0


source







All Articles