开发者

.htaccess redirect based on query string and remove query string

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:

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

Will redir开发者_开发问答ect to:

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

And

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

Will redirect to:

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

Thanks in advance.


you can do this type of redirection:

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

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

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

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


It seems to me you cannot perform a redirection based on a query string. So you would have to add [QSA] flag and redirect to a script which will be able to redirect thanks to the query string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜