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查询字符串到另一个_.htaccess - Fatal编程技术网

.htaccess Htaccess查询字符串到另一个

.htaccess Htaccess查询字符串到另一个,.htaccess,.htaccess,我有一个类似的url: shop/products.html?search_limiter=full&keyword1=apple 我想将此url重写为: index.php?route=product/search&search=apple&description=true 使用apache.htaccess 我尝试: Redirect 301 /shop/products.html?search_limiter=full&keyword1=apple

我有一个类似的url:

shop/products.html?search_limiter=full&keyword1=apple
我想将此url重写为:

index.php?route=product/search&search=apple&description=true
使用apache
.htaccess

我尝试:

Redirect 301 /shop/products.html?search_limiter=full&keyword1=apple     http://www.example.com/index.php?route=product/search&search=apple&description=true
但它没有起作用


有什么办法吗?

要在查询字符串上重写,必须先使用
RewriteCond
在查询字符串上进行匹配-然后可以在
重写规则中使用该规则进行
%N
类型匹配

这将执行您想要的重写(使用任何搜索词,而不仅仅是“apple”):


如果您不想更改地址栏中的URL,只想更改正在加载的资源,请将R=301(http 301重定向)保留在标记之外;您需要
mod_rewrite
,但首先需要使用
RewriteCond
来匹配查询字符串:谢谢您的帮助。我的关键字有utf8字符。所以不要重写。你能帮我一下吗?只需对utf8使用([^?\/]+)。谢谢你的帮助。我认为
\w
(任何“单词”字符)也应该可以@乌索桑
RewriteEngine On
RewriteCond %{REQUEST_URI} shop/products.html
RewriteCond %{QUERY_STRING} search_limiter=full&keyword1=(\w+)
RewriteRule ^.*$ /index.php?route=product/search&search=%1&description=true [NC,L,R=301]