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
Regex 从url修剪查询字符串_Regex_String_Apache_.htaccess_Http Status Code 301 - Fatal编程技术网

Regex 从url修剪查询字符串

Regex 从url修剪查询字符串,regex,string,apache,.htaccess,http-status-code-301,Regex,String,Apache,.htaccess,Http Status Code 301,一些URL是通过我们的脚本生成的。我需要通过htaccess修剪所有这些; 我有几百个,所以所有的xxx都要清洗 即: 到 或者任何以?开头的东西?剩下的就不需要了 我尝试重写规则^ \?.*$/[R=301,L],但没有成功: 我必须使用什么来代替\?.*?路径不包含查询字符串。使用RewriteCond匹配任何非空查询字符串 RewriteCond %{QUERY_STRING} !^$ RewriteRule \.html$ $0 [R=301,L] 我还添加了一个条件,即url必须以

一些URL是通过我们的脚本生成的。我需要通过htaccess修剪所有这些; 我有几百个,所以所有的xxx都要清洗

即:

或者任何以?开头的东西?剩下的就不需要了

我尝试重写规则^ \?.*$/[R=301,L],但没有成功:


我必须使用什么来代替\?.*?

路径不包含查询字符串。使用RewriteCond匹配任何非空查询字符串

RewriteCond %{QUERY_STRING}  !^$
RewriteRule \.html$ $0 [R=301,L]
我还添加了一个条件,即url必须以.html结尾,以防将来需要添加一些php脚本

domain.com/page.html 
RewriteCond %{QUERY_STRING}  !^$
RewriteRule \.html$ $0 [R=301,L]