1

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

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 Apr 18 at 15:04
  • Better as the first rule, right after RewriteEngine on then you have no interference with other rules – HelgeB Apr 18 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.