的.htaccess基于查询字符串重定向和删除查询字符串 [英] .htaccess redirect based on query string and remove query string

查看:144
本文介绍了的.htaccess基于查询字符串重定向和删除查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有重定向指令重定向旧的URL与查询字符串,以新的URL没有查询字符串。而新的URL取决于查询字符串的值。例如:

I'm in need to have redirect instruction to redirect the old URL with query string to new URL without query string. And the new URL depends on value of query string. For example:

我想: HTTP:// www.mydomain.com/product.php?id_product=AAA

I want: http:// www.mydomain.com/product.php?id_product=AAA

重定向到:

HTTP:// www.mydomain.com/product-name-for-product-number-1

http:// www.mydomain.com/product-name-for-product-number-1

HTTP:// www.mydomain.com/product.php?id_product=BBB

http:// www.mydomain.com/product.php?id_product=BBB

重定向到:

HTTP:// www.mydomain.com/this-is-different-product-name-for-product-number-2

http:// www.mydomain.com/this-is-different-product-name-for-product-number-2

在此先感谢。

推荐答案

你可以做到这一点类型的重定向:

you can do this type of redirection:

来自:HTTP:// www.mydomain.com/product-name-for-product-number-AAA
指向:http:// www.mydomain.com/product.php?id_product=AAA&name_product=product-name

from: http:// www.mydomain.com/product-name-for-product-number-AAA
to: http:// www.mydomain.com/product.php?id_product=AAA&name_product=product-name

来自:HTTP:// www.mydomain.com/this-is-different-product-name-for-product-number-2
指向:http:// www.mydomain.com/product.php?id_product=BBB&name_product=this-is-different-product-name

from: http:// www.mydomain.com/this-is-different-product-name-for-product-number-2
to: http:// www.mydomain.com/product.php?id_product=BBB&name_product=this-is-different-product-name

您不能dinamically检索htaccess文件中的产品名称,要做到这一点的唯一方法是:

you cannot retrieve dinamically the product name from htaccess file, the only method to do this is:

RewriteRule ^(.+)-for-product-number-(.+)$ ^product.php?id_product=$2&name_product=$1

或你需要创建一个重写规则你必须每个产品(可以生成从数据库的所有产品ID和功放检索脚本的.htaccess;名):

or you need to create a rewriterule for each product you have (you can generate the .htaccess from a script that retrieve from db all products id & name):

RewriteRule ^product-name-for-product-number-1$ product.php?id_product=AAA
RewriteRule ^this-is-different-product-name-for-product-number-2$ product.php?id_product=BBB

这篇关于的.htaccess基于查询字符串重定向和删除查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆