Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String htaccess中的基本url后面的查询字符串_String_.htaccess - Fatal编程技术网

String htaccess中的基本url后面的查询字符串

String htaccess中的基本url后面的查询字符串,string,.htaccess,String,.htaccess,我目前正在尝试重定向每个包含查询字符串k 以下是期望的结果: 发件人: 需要: 它适用于任何目录/子目录,但不适用于基本url。它似乎也适用于不同的htaccess tester online基本url,但不适用于服务器 这是htaccess RewriteEngine on rewritecond %{REQUEST_FILENAME} -d [OR] rewritecond %{REQUEST_FILENAME} -f RewriteRule (.*) - [S=12] Rewrit

我目前正在尝试重定向每个包含查询字符串k

以下是期望的结果:

发件人:

需要:

它适用于任何目录/子目录,但不适用于基本url。它似乎也适用于不同的htaccess tester online基本url,但不适用于服务器

这是htaccess

RewriteEngine on

rewritecond %{REQUEST_FILENAME} -d [OR]
rewritecond %{REQUEST_FILENAME} -f 
RewriteRule (.*) - [S=12] 

RewriteBase /
RewriteCond %{QUERY_STRING} ^k=(.*)$
RewriteRule (.*)?$ $1? [R=301,L]
谢谢

你能试试这个吗

RewriteEngine on


RewriteCond %{THE_REQUEST} /\?k
RewriteRule ^ %{REQUEST_URI}? [NC,L,R]
与原始代码相同,但我使用%{THE_REQUEST}变量来操作查询字符串


在测试之前请清除浏览器的缓存。

您使用的是哪个apache版本?一个网站上是apache/2.2.10,另一个网站上是apache/2.2.31谢谢我测试了它,但它不起作用。清除缓存并在不同浏览器上测试。@Vincent您在htaccess中还有其他规则吗?@Vincent我认为您的第一条重写规则与此冲突。尝试重新排序,将我的规则放在其他规则的首位。