ErrorDocument 404/404.html not applied to .htaccess

The 404.html file exists, but only ErrorDocument doesn’t seem to apply. If you look at infinityfree.com in the administration tool, there is an error page, but it goes to that link.ㄹ

file:

# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
# END WordPress

# BEGIN protect xmlrpc.php
# END protect xmlrpc.php
ErrorDocument 404 /404.html
ErrorDocument 403 /404.html
ErrorDocument 500 /500.html
ErrorDocument 503 /404.html

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]

RewriteCond %{THE_REQUEST} \s/.*\.php [NC]
RewriteRule ^.*$ - [R=404,L]
ErrorDocument 404 /404.html

What role: .php brings up 404.html.Except for file extensions: only allowed when connecting with index.

Please put your code in code blocks next time. I edited your post, it was unreadable because half of the .htaccess file was being parsed as formatting.


Besides that, I the .htaccess code seems fine (except for the duplicate ErrorDocument 404 lines, but that won’t cause issues). Can you please explain what’s not working for you? A few things that would help:

  • What URL is not having the intended behavior?
  • What should happen when people visit that URL?
  • What actually happens when you visit that URL?
4 Likes

I blocked access to https://gamegam-kartrush.wuaze.com/index.php and allowed only access to index < this way, and when I access index.php, it prints 404 pages. It prints 404.html pages through ErrorDocument 404 /404.html. It’s located at https://gamegam-kartrush.wuaze.com/404.html .

did you edit it not using wordpress filters?

Yes

# BEGIN WordPress
ErrorDocument 404 /400.html
ErrorDocument 403 /404.html
ErrorDocument 500 /404.html
ErrorDocument 503 /404.html

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{THE_REQUEST} \s/.*\.php [NC]
RewriteRule ^.*$ - [R=500,L]

</IfModule>
# END WordPress

Again:

When you say that:

This is exactly what I would expect your code to do, and seems like intended behavior. If this is not what you want to happen, what do you want to happen instead?


And again, please format your post. Don’t just dump your code in the post field and hit Reply, without checking the preview pane or see what was published. If you did, you would see that the code becomes unreadable.

6 Likes

If 404 occurs as a current example, the movement has been changed to a specific link,

What I want is to format 404.html in the domain.

Example:
127.0.0.1/404.html X

127.0.0.1/index : I wanted to call 404.html right from this link.
I changed to moving 12 7.0.0.1/404.html now.

Ah, now I understand.

Please note the following help text shown below the “Action” field in the client area error pages configuration tool:

If a full URL is specified (starting with http:// or https://), the visitor will be redirected to the URL. If a file path is given (starting with a slash), the provided file is returned.

By specifying your 404 page like this, the server will just show the contents of the 404.html, but not change the URL.

ErrorDocument 404 /404.html

If you want people to be redirected to the new URL, you should setup the .htaccess rule like this (replace the domain in the URL with your own of course):

ErrorDocument 404 http://example.com/404.html

As the text in the client area implies: you can use both, but what exactly you specify has different consequences.

6 Likes

It’s the opposite.

If you use ErrorDocument 404 /404.html, it does not show what you made at 404.html.

If you design it at 404.html on the same path and pop up 404, the page I want doesn’t appear.


maybe this thing broke .htaccess???

That way, it goes to the web.

I’m sorry, but I really don’t understand what you mean by this, what the current behavior is or what you would like the behavior to be. In short, I don’t understand the issue, and if I don’t understand the issue then I cannot help solve it.

You’re keep pointing out what you don’t want to happen, but I can’t help you if I don’t know what you do want to happen.

So I would like to ask you again to ask the questions I asked before:

Please answer these questions one by one using real URLs, not example dummy URLs.

6 Likes

WordPress handle 404 errors specifically, so specifying an ErrorDocument is unlikely to do anything.

1 Like

Except that this site is not using WordPress, it seems to be fully custom built.

3 Likes

I used it.
If 404 calls, I want to call index.php without going to the link below.
I blocked it when accessing as a file finalist. (e.g. .php)
And when accessing .php, 404 appears, but the problem is that you have to call it in /404.html format, not in link format, but you can’t call it.

https://gamegam-kartrush.wuaze.com/error/error_code?code=404&lang=auto

I’m still having a lot of trouble making sense of your messages. I’m not sure if you tried to answer the three questions I asked, but if so, I don’t understand what part is supposed to answer which question. Please maybe format your post to clearly answer the questions one by one instead of working them into a message?

Am I correct to understand that this is what you want:

  • If the request has a certain path (e.g. http://example.com/about), and a matching PHP file exists with that name (e.g. about.php), then load that file.
  • If someone requests a PHP file specifically (e.g. http://example.com/about.php), then a 404 error page should be shown.
  • The 404 error page is loaded by the index.php script, and the URL should not change.

If so, I think the solution should be as simple as specifying ErrorDocument 404 /index.php.

Can you please tell me if I understood the desired situation correctly?

4 Likes

Not all of them.

When accessing with the fail extension (e.g., php), it is marked as 404 as an example, and it is not processed as 404.html of the 404 mark shown in the diagram.
Copy the contents of this post, put it on the website, attach .php to the website, and access it.

I’m sorry, but again, I need you to write more clearly.

As far as I can tell, your code does exactly what it implies, and I see no reason to replicate it myself to confirm that it does.

But what is clear is that the code is not doing what you want it to do. I can help you update the code so it does do what you want, but again: I have no idea what the desired behavior is.

Again: please answer my three question. One by one. With real URLs. Please consider using a format like this:

7 Likes