S
S
stainer2018-12-28 15:47:41
htaccess
stainer, 2018-12-28 15:47:41

How to implement redirects correctly?

Good afternoon.
Help to understand the problem.
We made a cnc on the site, so all old links need to be 301 redirected to new ones with cnc.
We made some entries in htaccess in the form of RewriteRule ^articles/$ articles.php [L,NC,QSA].
And the rest of the pages of categories and products were added to the database and in php we check $_SERVER['REQUEST_URI'] for presence in the database. If there is, then we give 301 headers.
But there is a problem.
In htaccess there is such an entry ErrorDocument 404 /404.php, and if something is not described in htaccess (there is no RewriteRule for the request), then it is issued 404. And it must first get into php, it is already checked for presence in the database and then given 404.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
stainer, 2018-12-28
@stainer

I decided that ErrorDocument 404 redirected to the page where the check for URLs in the database is going on.

S
Stalker_RED, 2018-12-28
@Stalker_RED

Well, remove it from htaccess
And issue 404 only if it is not found in the database, already using php.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question