The variable replacement will not work in ErrorDocument
directive -- it will pass URL as is with no changes (maybe there are some special module that will perform such replacement -- I do not know).
If you want to use ErrorDocument
directive, then you will have to grab the originally requested URL in the script itself (e.g. $_SERVER['REQUEST_URI']
in PHP). You can pass some special parameter to tell your 404 handler to execute such look up, e.g. ErrorDocument 404 /recherche?special-search=yes
.
Another approach would be to use mod_rewrite, where such replacement is possible. For example:
Options +FollowSymLinks
RewriteEngine On
# redirect all requests to non-existing resources to special handler
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /recherche?search_query=%{REQUEST_URI} [L,R=404]
If you are using mod_rewrite already .. then such rule should be placed somewhere at the end of your rules list so it does not conflict with other rules.