O
O
ozoro2018-12-11 21:05:16
MODX
ozoro, 2018-12-11 21:05:16

How to redirect from the wrong URL to the correct one?

Let me know if it is possible to make redirects.
Redirect 1.
For example, there are such existing URLs:

/category/category/page.html
/category/page.html
/page.html

If the user types a URL without .html in the browser, then in order to redirect to an existing address with .html
That is, to check if the CNC is existing, only entered without .html, then a redirect would be made to the same address, only with .html
Redirect 2
For example, there are such existing URLs:
/category/category/
/category/
/

Make it so that when you enter a set of characters that do not match the existing URL after the final slash, it redirects to the correct URL (the last directory), for example, when you enter:
/category/category/?
/category/?blablabla
/&
/category/category/?какой-то-несуществующий-get-параметр
/category/=
/<>{}[]и-другие-символы

to redirect to:
/category/category/
/category/
/

However, if the URL after the slash exists, that is, there is a URL with such GET parameters, then the redirect would not occur.
I would be grateful for a solution through .htaccess, in extreme cases through php

Answer the question

In order to leave comments, you need to log in

4 answer(s)
B
Boris Syomov, 2018-12-11
@kotomyava

You are asking for the impossible.
This is what your application should do. The web server simply does not have the necessary information to make such rules at its level, so there is no solution through .htaccess.
But no one will be able to write an example for you in php, either. this code will depend on your application - there is no universal external solution to your problem.
Those. theoretically, it can be made a proxy between the site and the web server, which will make additional requests, and check the responses to certain urls, but this will be the rarest crutch.

O
ozoro, 2018-12-11
@ozoro

How to implement this on MODX ?

M
maniiii, 2018-12-15
@maniiii

Well, kamon, type "redir" in the repository and see how many ready-made solutions there are

A
Arthur K., 2018-12-22
@amark

What is it for you?
Doesn't look like a real problem to be solved.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question