K
K
Kostya2014-02-10 13:31:44
htaccess
Kostya, 2014-02-10 13:31:44

How to make a 301 redirect, like on Habré?

I'm going to launch one Wordpress project with a link structure:
http://site.ru/category/12345/
And I need to make sure that if something else is added to this address "by mistake", then 301 instead of 404 would work on the same page. Such implementation is used on Habré. example:

http://habrahabr.ru/post/212003/

http://habrahabr.ru/post/212003/ошибочний текст/
How to do it, who knows?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
aleksandrvin, 2014-02-10
@aleksandrvin

Is there nginx in front of the server? Then you can do it.

V
Vlad Zhivotnev, 2014-02-10
@inkvizitor68sl

And habr does not redirect anywhere.
They simply rewrite in nginx in such a way that it does not take into account the third section of the uri (and beyond).
But if you need a rewrite, then something like this:
location something like this {
...
error 404 = @errorloc
...
}
location @errorloc {
rewrite ^/(.*)/(.*)/.* $scheme:// $http_host/$1/$2 permanent;
}
Approximately so.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question