删除.htaccess中的GET参数 [英] Removing GET parameter in .htaccess

查看:79
本文介绍了删除.htaccess中的GET参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法删除由一个404 SEF模块错误添加的一个GET参数.

I'm not able to remove one GET parameter wrongly added by one 404 SEF module.

我只想删除"task = view"(而不是带有其他参数).

I want to remove "task=view" only if it appears alone and not with another parameter.

所以

www.mysite.com/1.html?task=view 应该重定向到 www.mysite.com/1.html .

www.mysite.com?task=view&view=article 时应保持不变.

无论我使用哪个RewriteRule,此参数都不会消失.看起来它是在运行index.php时从任何环境变量生成的.

No matter which RewriteRule I use, this paramater does not go. Looks like it is being generated from any environment variable when index.php is run.

例如,这不起作用:

RewriteCond %{QUERY_STRING}  ^task=view$ [NC]
RewriteRule (.*)task=view.*  $1 [R=301,L]

这是我的.htaccess文件:

Here is my .htaccess file:

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|.php|.html|.htm|.feed|.pdf|.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

Options  -Indexes

如何处理呢?

推荐答案

使用以下规则:

RewriteCond %{QUERY_STRING}  ^task=view$ [NC]
RewriteRule ^(.*)$ $1? [R=301,L]

$1末尾的

?将剥离所有现有查询字符串.

? at the end of $1 will strip-off any existing query string.

这篇关于删除.htaccess中的GET参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆