I have a simple 404 redirect in my .htaccess file:

ErrorDocument 401 /404.htm

ErrorDocument 404 /404.htm

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://hypnosis-retreat.co.uk/$1 [R,L]

When I enter the domain https://example.co.uk/bhabha it correctly renders the 404 page. Where I enter the URL https://example.co.uk/bhabha/morebhabha it fails to render the 404 page correctly.

I need to trap a path that goes nowhere.

  • 1
    The 404 document is being correctly called, it's just not being "rendered" correctly (as you say) - missing stylesheets and images. This is because you are using relative URLs to all your static resources (images, CSS, JS. etc.). You need to use root-relative (or absolute) URLs in your error document HTML. See my answer to the linked question that discusses this in more detail.
    – MrWhite
    Apr 14, 2020 at 10:34

1 Answer 1


I think that happens because you have relative paths to your CSS/JS/IMG assets. Hence although the 404 loads the correct page, it cannot load the correct files when you try to access a URL outside of root level.

  • Thank you for the quick reply which I understand. The website in question uses a code generator and therefore not best suited to changing the code manually. I could place the Base Tag in the 404.htm page only. Do you think that would resolve the issue? Thanks Apr 14, 2020 at 11:37
  • @GaryLowrey Using the base tag is a solution, but note the caveats as mentioned in my answer to the linked question above. However, these issues are less likely to apply to a 404 error document, so you are probably OK. Give it a go and test it!
    – MrWhite
    Apr 14, 2020 at 22:04
  • @MrWhite - thank you. I used a <base href= "hypnosis-retreat.co.uk"> and updated the htaccess to "ErrorDocument 404 hypnosis-retreat.co.uk/404.htm". There was only an email link on the 404 page and all works well now. Apr 16, 2020 at 15:39
  • @GaryLowrey You shouldn't change the ErrorDocument directive - that was already correct. By changing that to an absolute URL it will now trigger a 302 redirect to your 404 page (which may not respond with a 404 status). By redirecting to your error document you probably negate the need for a base tag - but "redirecting" to the error document is "bad" (for users and SEO).
    – MrWhite
    Apr 16, 2020 at 15:55
  • @MrWhite - thank you. Understood Apr 18, 2020 at 22:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.