Change permalinks

Hello friends,

I have an old site in WP using EE + Nginx, where permanent links include the year and month of posting the url as shown below:

example.com/2012/01/category-name/title-post

The problem is that I want to update those posts and repost the current date. By doing so the URL will change to:

example.com/2016/08/category-name/title-post

To avoid all this trouble, I will change the permalinks in WordPress settings for:

example.com/title-post

Now the question:

It has some way to redirect all the old traffic of:

example.com/2012/01/category-name/title-post

For:

example.com/title-post

Not to lose the links and gives 404 error?

From what I’ve been reading, you can do this redirection using regular expression, most do not have a clue how to do this.

Some guys idea?

TRADUZIDO DE:

Olá amigos, Tenho um site antigo em WP usando EE + Nginx, em que os links permanentes incluem o ano e mês da postagem na url como no exemplo abaixo: example.com/2012/01/category-name/title-post

O problema é que quero atualizar esses posts e repostar na data atual. Fazendo isso a url mudará para: example.com/2016/08/category-name/title-post

Para evitar todo esse problema, vou mudar os links permanentes nas configurações do WordPress para: example.com/title-post

Agora a pergunta: Tem alguma forma de redirecionar todo o trafego antigo de: example.com/2012/01/category-name/title-post Para: example.com/title-post Para não perder os links e dá erro 404?

Pelo que andei lendo, talvez consiga fazer esse redirecionamento usando expressão regular, mais não tenha a menor noção de como fazer isso. Alguma ideia rapazes?

WordPress internally manages such redirects.

However, you can ensure you’ll never miss a visitor because of 404 errors installing a plugin named “Permalink Finder”. I use it on all my ancient blogs, in order to workaround the issues related to permalink changes.

I went through something similar recently. These two site posts were helpful:

Thanks for the answers, friends.

I would like to do this redirect without plugin WP and without manually place line by line for each post.

The ideal would be to direct the nginx, due to be thousands of posts. The following .htaccess code does this magic in apache:

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([^/]+)/([^/]+)/$ http://example.com/$4

I am not able to convert it to nginx.

TRADUZIDO DE:

Obrigado pelas respostas, amigos.

Gostaria de fazer esse redirect sem a necessidade de plugin e sem colocar manualmente linha por linha para cada post.

O ideal seria fazer direto pelo nginx, devido ser milhares de posts. O seguinte código .htaccess faz essa mágica no apache:

CODIGO

NĂŁo estou conseguindo converter isso para nginx.

The nginx code that came closest was this:

location ~ ^/([0-9]{4})/([0-9]{2})/([^/]+)/([^/]+)/$ {
	rewrite ^(.*)$ http://example.com/$4 permanent;
}

However when I add this code in vhost within the server in /etc/nginx/sites-available/example.com file gives an error and nginx server falls.

More any idea guys? :slight_smile:

TRADUZIDO DE:

O cĂłdigo nginx que mais se aproximou foi esse:

CODIGO

Porem quando adiciono esse código no vhost dentro do server no arquivo /etc/nginx/sites-available/example.com dá um erro e o servidor nginx cai.

Mais alguma ideia rapazes? :slight_smile:

Considering you can read in Portuguese, take a look at this post of mine:

https://wp.sarmento.org/redirecionando-urls-antigas-para-nova-estrutura-de-permalinks/

1 Like

Top @janiosarmento :slight_smile:

Thank you, now it’s perfect.

Here’s the code I used adapted, following the pattern of your post:

location ~ "^/([0-9]{4})/([0-9]{2})/([^/]+)/(.*)$" {
	rewrite "^/([0-9]{4})/([0-9]{2})/([^/]+)/(.*)$" http://example.com/$4 permanent;
}