Redirect 301 removing parameters in URL by .htaccess
-
26-02-2021 - |
Pregunta
In the file .htaccess
in magento, I want to redirect a url with parameters. An example is this:
https://example.com/presente/decoracao/teu-sorriso?PageSpeed=noscript
I need to redirect this to the same page, as in the example below:
https://example.com/presente/decoracao/teu-sorriso
In my .htaccess
file, I try the following code without success:
RewriteRule ^presente/decoracao/teu-sorriso(.*)$ /presente/decoracao/teu-sorriso? [L,R=301]
When I use the %{REQUEST_URI}
syntax it always redirects me to /index.php
because of the particularities of Magento. Another way I tried was the following, but without success too:
RewriteCond %{QUERY_STRING} ^PageSpeed=noscript$ [NC]
RewriteRule ^/?presente/decoracao/teu-sorriso/?$ /presente/decoracao/teu-sorriso? [L,R=301]
I've been trying to do this in several ways, but all of them to no avail. Thanks in advance!
Solución
You can try to use two rewrite conditions - one for the QUERY_STRING
and one for the REQUEST_URI
and let the matching pattern be .*
in the rewrite rule.
RewriteCond %{QUERY_STRING} ^PageSpeed=noscript$ [NC]
RewriteCond %{REQUEST_URI} ^/presente/decoracao/teu-sorriso/?$
RewriteRule .* /presente/decoracao/teu-sorriso? [L,R=301]
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange