T
T
Test Test2016-03-25 14:50:26
Yii
Test Test, 2016-03-25 14:50:26

How to make Apache or Yii return 404 without 301?

Good afternoon! There was such a question. We have a site on Yii1. And we want to add a slash to the end of the URL. We do it like this:

# Enforce trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

Everything works as it should, but there is one BUT! If we go to a fake page, for example, site.ru/abrakadabra
Then the server will first make a 301 redirect to site.ru/abrakadabra , and then it will return a 404 error. We need it to be just 404.
PS The SEOs said that this is important.
PSS to implement means PHP?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
OnYourLips, 2016-03-25
@OnYourLips

Well, without PHP, how do you know if there is such a page or not?

V
Viktor Taran, 2016-03-26
@shambler81

The question is old and rhetorical, it has nothing to do with the engine.
THIS has to do with the parser of the server response code, whether it takes a sequence of codes or the last one.
In fact, the final 404 will indeed return a non-existent page and the search engine will understand that it does not exist and mark it as non-existent, but the redirect url itself may not change because it returns a valid server response.
You can check the response code in .htaccess, but thus, with each hit, you need to wait for the server's response, and only after that something will happen at all. A line-by-line dynamic re-reading of this file can potentially add hemorrhoids.
So I would not recommend checking the response code through .htaccess.
AND SO WHAT CAN BE DONE.
The first is to set up a tray file, etc. in nginx, there is a richer toolkit for this, and it reads server response codes on the fly, it’s better than in .htaccess
.
if they appear there dynamically, solve the problem with your engine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question