A
A
Amoled2015-02-06 10:12:43
Apache HTTP Server
Amoled, 2015-02-06 10:12:43

Why doesn't redirect to 404 work in .htaccess?

It is required to rewrite to /404 for all non-existent files/folders on the server, except for static files (css, js, etc.). I've already tried dozens of options, it doesn't work anyway. I already memorized the first 10 pages of Google results on the problem. For example:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(css¦jpg¦gif¦zip¦js)
RewriteRule . /404 [L]

If you try to do the opposite, so that only non-existent files / folders with a certain extension are sent to /404, then everything works
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} \.(xml|txt)$
RewriteRule . /404 [L]

Worth adding! and no rebound effect from ! does not work as expected, In general, this rule seems to disappear with !.
All the same, a 404 rewrite is done for requests with .css, etc. at the end, although it is clearly written not to do it.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
IceJOKER, 2015-02-06
@IceJOKER

Isn't it easier ErrorDocument 404 /404?

Z
zooks, 2015-02-06
@zooks

¦What is this symbol. You also need to indicate that with your config, this will not be a normal 404 error, but will only display a page with that name.
How to redirect Apache before it gives a 404 error?

D
Dmitry, 2015-02-06
@Kurskov

Shouldn't non-existent statics (css¦jpg¦gif¦zip¦js)lead to a redirect?
If it should, then, as IceJOKER said, ErrorDocument 404 /404, only up to RewriteEngine on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question