[英]htaccess remove the parameter from url
I am trying to remove certain url parameters from the urls. 我试图从网址中删除某些网址参数。 Those parameters have no effect on the content being displayed anymore, but google have a bunch of them indexed. 这些参数对正在显示的内容没有任何影响,但谷歌有一堆索引。
I would like to redirect them to the base url. 我想将它们重定向到基本URL。
Here are the examples. 以下是示例。
From www.myexamplesite.com/?start=10
来自www.myexamplesite.com/?start=10
To: www.myexamplesite.com
致: www.myexamplesite.com
From www.myexamplesite.com/folder1/?start=10
来自www.myexamplesite.com/folder1/?start=10
To: www.myexamplesite.com/folder1
致: www.myexamplesite.com/folder1
From www.myexamplesite.com/folder2/?start=10
来自www.myexamplesite.com/folder2/?start=10
To: www.myexamplesite.com/folder2
致: www.myexamplesite.com/folder2
Actually I don't need to have any urls with parameters, so I am wondering if there can be a way to catch and redirect all other possible parameters from the urls, and only allow some selected ones that I will specify in htaccess. 实际上我不需要任何带参数的url,所以我想知道是否有办法从url中捕获并重定向所有其他可能的参数,并且只允许我将在htaccess中指定的一些选定的参数。
Examples: 例子:
From www.myexamplesite.com/?param1=10
来自www.myexamplesite.com/?param1=10
To: www.myexamplesite.com
致: www.myexamplesite.com
From www.myexamplesite.com/?param1=10¶m2=20
来自www.myexamplesite.com/?param1=10¶m2=20
To: www.myexamplesite.com
致: www.myexamplesite.com
From www.myexamplesite.com/folder1/?param1=10
来自www.myexamplesite.com/folder1/?param1=10
To: www.myexamplesite.com/folder1
致: www.myexamplesite.com/folder1
From www.myexamplesite.com/folder1/?param1=10¶m2=20
来自www.myexamplesite.com/folder1/?param1=10¶m2=20
To: www.myexamplesite.com/folder1
致: www.myexamplesite.com/folder1
But for param3 which should be my selected one: 但对于param3应该是我选择的:
From www.myexamplesite.com/folder1/?param3=10
leave untouched: www.myexamplesite.com/folder1/?param3=10
从www.myexamplesite.com/folder1/?param3=10
保持不变: www.myexamplesite.com/folder1/?param3=10
Update 更新
I actually have already implemented a solution, but my main problem is that it always redirect to the home page and not the appropriate REQUEST_URI... 我实际上已经实现了一个解决方案,但我的主要问题是它总是重定向到主页而不是相应的REQUEST_URI ......
Here is what I have: 这是我有的:
RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} !^item=
RewriteCond %{REQUEST_URI} !^/manage
RewriteRule .? http://www.myexamplesite.com%{REQUEST_URI}? [R=301,L]
You can use this rule to strip all query strings except when param3=
is found in it. 您可以使用此规则param3=
所有查询字符串,除非在其中找到param3=
。
RewriteEngine On
RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} !(?:^|&)param3= [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L,NE]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.