RedirectMatch 301删除URL参数 [英] RedirectMatch 301 Removing URL Parameters
问题描述
我的服务器apache中有一个带有重定向的文件.conf
,我想使用参数重定向一个url.一个例子是这样的:
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
在我的.conf
文件中,我尝试以下代码未成功:
In my .conf
file, I try the following code without success:
RedirectMatch 301 /presente/decoracao/teu-sorriso$ /presente/decoracao/teu-sorriso?
我无法使用.htaccess
或Apache RewriteRule
方法的重定向.即使进行了研究,研究和尝试,到目前为止,仍未解决任何问题.预先感谢!
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!
推荐答案
您不能使用Redirect
指令使用query string
重定向URL,因为它与?PageSpeed=noscript
不匹配.您需要使用Mod-rewrite
.
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
.
假设您的服务器上启用了mod-rewrite
模块,则可以在Apache配置或htaccess中使用类似以下的内容
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]
这篇关于RedirectMatch 301删除URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!