htaccess从网址中删除参数 [英] htaccess remove the parameter from url
问题描述
我正在尝试从网址中删除某些网址参数.这些参数对显示的内容不再有影响,但是google对其进行了索引.
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.
我想将它们重定向到基本URL.
这是示例.
I would like to redirect them to the base url.
Here are the examples.
来自www.myexamplesite.com/?start=10
到:www.myexamplesite.com
From www.myexamplesite.com/?start=10
To: www.myexamplesite.com
来自www.myexamplesite.com/folder1/?start=10
到:www.myexamplesite.com/folder1
From www.myexamplesite.com/folder1/?start=10
To: www.myexamplesite.com/folder1
来自www.myexamplesite.com/folder2/?start=10
到:www.myexamplesite.com/folder2
From www.myexamplesite.com/folder2/?start=10
To: www.myexamplesite.com/folder2
实际上我不需要带有参数的url,所以我想知道是否可以找到一种方法来从url中捕获并重定向所有其他可能的参数,并且只允许我在htaccess中指定的一些选定参数.
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.
示例:
来自www.myexamplesite.com/?param1=10
到:www.myexamplesite.com
Examples:
From www.myexamplesite.com/?param1=10
To: www.myexamplesite.com
来自www.myexamplesite.com/?param1=10¶m2=20
到:www.myexamplesite.com
From www.myexamplesite.com/?param1=10¶m2=20
To: www.myexamplesite.com
来自www.myexamplesite.com/folder1/?param1=10
到:www.myexamplesite.com/folder1
From www.myexamplesite.com/folder1/?param1=10
To: www.myexamplesite.com/folder1
来自www.myexamplesite.com/folder1/?param1=10¶m2=20
到:www.myexamplesite.com/folder1
From www.myexamplesite.com/folder1/?param1=10¶m2=20
To: www.myexamplesite.com/folder1
但是对于param3,它应该是我选择的一个:
But for param3 which should be my selected one:
来自www.myexamplesite.com/folder1/?param3=10
保持原样:www.myexamplesite.com/folder1/?param3=10
更新
我实际上已经实现了一个解决方案,但是我的主要问题是它总是重定向到主页,而不是适当的REQUEST_URI ...
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...
这是我所拥有的:
RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} !^item=
RewriteCond %{REQUEST_URI} !^/manage
RewriteRule .? http://www.myexamplesite.com%{REQUEST_URI}? [R=301,L]
推荐答案
您可以使用此规则除去所有查询字符串,除非在其中找到param3=
.
You can use this rule to strip all query strings except when param3=
is found in it.
RewriteEngine On
RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} !(?:^|&)param3= [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L,NE]
这篇关于htaccess从网址中删除参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!