gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:11:18 25 4
gpt4 key购买 nike

我有一个像这样的网址:

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 匹配查询字符串 - 然后您可以在 RewriteRule 中使用 %N 类型匹配。

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

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]

如果您不想实际更改地址栏中的 URL,只更改正在加载的资源,请保留 R=301(http 301 重定向)的旗帜。

关于.htaccess - Htaccess 查询字符串到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39832245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com