Answer the question
In order to leave comments, you need to log in
How to set up rewrites for files without extensions?
Hello. Please tell me about rewrites.
In general, the site is simple in html. But I don't want the .html extension to be visible. That is, I want
the content of the domain.ru/contacts.html file to
be shown
when visiting the URL domain.ru/contacts .
This is what it looks like
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond % {REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1.html [NC,L]
But there is a problem:
When requesting a non-existent page, for example domain.ru/contacts123 , the server tries to find domain.ru/contacts123 .html,
but there is no such file on the server, so it tries to find .html again, resulting in a circular redirect and the server gives a 500 error instead of a 404 response.
So how to set up rewrites in such a way that there are beautiful URLs like domain.ru/contacts (exactly without a slash at the end), but at the same time, when requesting a non-existent page, receive a 404 response code?
Otherwise, Yandex Webmaster does not like that non-existent pages give a 500 response instead of a 404.
Answer the question
In order to leave comments, you need to log in
RewriteCond %{REQUEST_URI} !^.+\.(html|htm)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+[^/])$ /$1.html [NC,L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question