A
A
Alexander Vasiliev2020-11-16 16:30:27
htaccess
Alexander Vasiliev, 2020-11-16 16:30:27

Why do non-existent pages return a 200 response?

The site has pages like site.ru/some_page.php
but no page like
site.ru/some_page.php/many_different_symbols
and in theory a 404 page should open at this URL, but instead the server gives a 200 response and opens
site.ru/some_page .php/many_different_symbols
(only the site is static and all paths are relative - scripts, styles and pictures are not displayed).
How to get a 404 response on such pages or redirect them to a 404 page.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Vasiliev, 2020-11-16
@new_guest23

Adding the AcceptPathInfo Off directive to the .htaccess file did not help in my case.
But the following rules helped, maybe it will come in handy for someone:
To cut off everything that comes after site.ru/some_page.php and get an existing page:
RewriteRule ^(.*php)/.+$ /$1 [R=301,L]
Or to get 404 page:
RewriteRule ^(.*\.php)\/(.*)$ /404.php [R=301,L]

D
dodo512, 2020-11-16
@dodo512

AcceptPathInfo
In .htaccess add
AcceptPathInfo Off

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question