RedirectMatch 301 Removing URL Parameters

2020-04-21 07:22发布

I have a file .conf in my server apache with the redirects and 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 .conf file, I try the following code without success:

RedirectMatch 301 /presente/decoracao/teu-sorriso$ /presente/decoracao/teu-sorriso?

I can not use redirects from .htaccess nor the Apache RewriteRule method.Even researching, researching and trying, so far nothing has worked out. Thanks in advance!

1条回答
Summer. ? 凉城
2楼-- · 2020-04-21 08:08

You can not redirect a URL with query string using Redirect directive as it doesn't match against ?PageSpeed=noscript . You need to use Mod-rewrite .

Assuming mod-rewrite module is enabled on your server , you can use something like the following in your Apache config or htaccess

RewriteEngine on

RewriteCond %{QUERY_STRING} ^PageSpeed=noscript$ [NC]
RewriteRule ^/?presente/decoracao/teu-sorriso/?$ /presente/decoracao/teu-sorriso? [L,R=301]
查看更多
登录 后发表回答