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!
1 Answer 1
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]
-
I put this code before the last rewrite of the standard Magento, in this case
RewriteRule .* index.php [L], right?Matheus Portela– Matheus Portela2019年04月18日 15:04:02 +00:00Commented Apr 18, 2019 at 15:04 -
Better as the first rule, right after
RewriteEngine onthen you have no interference with other rulesHelgeB– HelgeB2019年04月18日 15:05:29 +00:00Commented Apr 18, 2019 at 15:05
Explore related questions
See similar questions with these tags.