Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/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
.htaccess htaccess将规则查询字符串重写为url_.htaccess_Url Rewriting - Fatal编程技术网

.htaccess htaccess将规则查询字符串重写为url

.htaccess htaccess将规则查询字符串重写为url,.htaccess,url-rewriting,.htaccess,Url Rewriting,我有以下网址: www.example.com/profile?id=31 我想把它重定向到: www.example.com/profile/id/31 我该怎么做 我试着用这个: RewriteCond %{QUERY_STRING} (^|&)id=31($|&) RewriteRule ^www\.example\.com/profile$ /www.example.com/profile/id/31?&%{QUERY_STRING} 但它不起作用我会选择这

我有以下网址:

www.example.com/profile?id=31
我想把它重定向到:

www.example.com/profile/id/31
我该怎么做

我试着用这个:

RewriteCond %{QUERY_STRING} (^|&)id=31($|&)
RewriteRule ^www\.example\.com/profile$ /www.example.com/profile/id/31?&%{QUERY_STRING}

但它不起作用

我会选择这样的方式,如果有帮助,请告诉我:

RewriteRule ^ profile/([0-9]+)/?$ /profile?id=$1 [NC,L,QSA]
这篇文章和其他答案对它的作用进行了广泛的解释。

尝试以下内容:

RewriteCond %{QUERY_STRING} ^(.+)=(.+)
RewriteRule ^(.+)$ http://www.example.com/$1/$2/$3 [R=301,L,QSD]
我使用的是匹配组,所以它将适用于给定相似模式的任何值