How to redirect old website URLs to the new URLs on new Grav website

Hello

  1. I finished a new Grav site and got the old website URLs that were indexed by Google. Normally, I do in the .htaccess a redirect in this way:

Redirect 301 old_URL new_URL

But I was not able to make it work

  1. I read the documentation and some forum posts:
    Routing | Grav Documentation

2.1 Redirect returns 404

I was not able to do the redirect in site.yaml, unfortunately I can not go back to the old website, and Google search positions are in danger now.

redirects:
  '/Articulos.php?articulo_no=134&': /blog/concentrador-de-oxigeno-portatiles[301]

3 I also tried via the Grav Admin Plugin in configuration site using redirects, then routes, then both, impossible to me to make it work, I do not know what am I doing wrong. Please see the screen capture.

In any case I always get the Grav 404 page when I enter the old URL on the browser.

Can somebody please be so kind to show me the right way to redirect old URLs to their corresponding Grav URL?
Thanks in advance.
Regards

@joejac,

  1. I read the documentation and some forum posts:
    Routing | Grav Documentation

Did you also pay attention to the following note:

You must escape certain characters in any routes that you want to match. This is especially important to know if you are migrating an old site that used links containing legacy file extensions (e.g. .php ) or URL parameters (?foo=bar ). In these examples, the period and question mark must be escaped like /index\.php\?foo=bar: '/new/location' .

On a fresh Grav installation using the following redirect in /user/config/site.yaml

redirects:
  /old_url?id=11: /typography[301]

… the url http://dev-dev/old_url?id=11 will throw a 404

When using… (note the \?)

redirects:
  /old_url\?id=11: /typography[301]

…the browser is redirected to http://dev-dev/typography

Note: You may ommit the [301] and set the default redirect code in /user/config/system.yaml:

redirect_default_code: 301     # Default code to use for redirects: 301|302|303

Note: There is more to do than setting Grav’s redirects. Here is a document on moving sites and/or changing urls: Websiteverschiebungen und Migrationen | Google Search Central  |  Dokumentation  |  Google for Developers.

1 Like

Thanks @pamtbaau your posts are always a good lesson.
You pointed the solution:

I did in /user/domain.com/config/site.yaml:

redirects:
'/index\.php\?categoria_no=8': /contacto

and the redirection worked fine.

Sorry, my mistake, I missed this part of the documentation, that you make reference:

the period and question mark must be escaped like /index\.php\?foo=bar: '/new/location'

Thanks and regards