I have finished a website and I am creating the necessary 301 redirects in the .htaccess
.
I have one of the old web sitemaps that has 100+ requests of the type:
?menu=nombre-del-plato
On the new web there are no similar requests and they should all be redirected to, say,http://mirestaurante.com/menu
Is there a way to avoid these 100+ same lines in the .httacces
?:
Instead of:
Redirect 301 /?menu=nombre-del-plato1 http://mirestaurante.com/menu
Redirect 301 /?menu=nombre-del-plato2 http://mirestaurante.com/menu
Redirect 301 /?menu=nombre-del-plato3 http://mirestaurante.com/menu
Redirect 301 /?menu=nombre-del-plato4 http://mirestaurante.com/menu
Make a line or function similar to:
Redirect 301 ?menu* http://mirestaurante.com/menu
EDIT: these requests are in two languages
Redirect 301 /?menu=nombre-del-plato3 http://mirestaurante.com/menu
Redirect 301 /ca/?menu=nombre-del-plato3 http://mirestaurante.com/ca/menu
It seems that all the URLs you want to redirect have one thing in common: they are all of type
?menu=nombre-del-plato
, so in the query string is the string?menu=
. So what you could do is create a single rule in .htaccess that redirects if that string is found.The rule would look like this:
This permanently redirects (by the R=301 flag) all the URLs that contain
?menu=
in the query string to the URLhttp://mirestaurante.com/
, eliminating the URL parameters (by the?
end of the URL to which it is redirected), and is the last rule to be checked (by flag L).Now, if you want it to redirect differently depending on the language, the easiest thing to do would be to have two rules (although I'm sure they could be combined into one):
It's important that you put the most specific rule first, because if you put the most generic one first, then the second rule will never be reached.