Home > Mobile >  How to not redirect to 404 page for a specific domain page
How to not redirect to 404 page for a specific domain page

Time:02-22

I wanted to add a 404 page to my website but i had some problems.

I made a .htaccess file:

ErrorDocument 404 /404.html

It works fine but i don't want that to give a 404 everytime.

What i want is that the htaccess dosn't redirect you to the 404 page, for a specific domain name page.

CodePudding user response:

If you don't want that ErrorDocument to be defined for a specific domain then enclose the ErrorDocument directive in a negated <If> expression that checks that the requested Host header is not example.com (the domain you want to exclude).

For example (requires Apache 2.4):

<If "%{HTTP_HOST} != 'example.com'">
    ErrorDocument 404 /404.html
</If>

The ErrorDocument is defined for every requested host, except example.com. (Obviously, you'll still get a 404 response for this other domain, when requesting a non-existent resource, but /404.html will not be served.)


Aside:

the htaccess dosn't redirect you to the 404 page

Probably just terminology, but there is no "redirect" (as in an external 3xx redirect) here to begin with. The error document is served with an internal subrequest. You could change the ErrorDocument directive so that it does trigger a "redirect", but that is rarely desirable.

  • Related