Iladarsda Iladarsda - 28 days ago 7
Apache Configuration Question

htaccess - 404 redirect from different folder into root

I looking for way to redirect any 404 error into index.php

ErrorDocument 404 /index.php

Works fine until you have a 404 inside another folder
- in this case it will display
but the page will be missing styles (as styles are in the root folder).

Any way I can actually user 301 redirect for ANY (anywhere) 404 error?

Answer Source

As you already said, this is not the redirection page's fault: it's your browser that thinks it's in the /about folder. There's nothing you can do in .htaccess to change that: a 301 redirect would change the status code, which is not a good idea.

The easiest solution would be using absolute links in the document:

<img src="/images/image.jpg">

for completeness' sake, a subsequent 301 can be achieved by using a full URL:

ErrorDocument 404 http://mydomain/index.php

but as said, it's probably not a good idea.