htaccess的301重定向问题URL变量 [英] htaccess 301 redirect issue with url variables
本文介绍了htaccess的301重定向问题URL变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我用这个code,这是成功的:
If I use this code, it's successful:
Redirect 301 /products.php http://website.com.au/product_123.php
但是,如果我这样做,是不是:
But if I do this, it isn't:
Redirect 301 /products.php?id=123 http://website.com.au/product_123.php
请注意在URL中的变量是什么导致它的失败。
Note the variable in the url is what's causing it to fail.
我是什么做错了吗?是否有另一种方式做到这一点?我真正需要的网址变量。
What am I doing wrong? Is there another way to do this? I really need the urls variables.
推荐答案
您不能把查询字符串参数在重定向
指令的来源URI路径。你必须使用mod_rewrite的%{QUERY_STRING}
变量为:
You can't put query string parameters in the source URI path of the Redirect
directive. You'll have to use mod_rewrite's %{QUERY_STRING}
variable for that:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=123$
RewriteRule ^/?product\.php$ http://website.com.au/product_123.php? [L,R=301]
或者使它更普遍的:
Or to make it more general:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([^&]+)
RewriteRule ^/?product\.php$ http://website.com.au/product_%1.php? [L,R=301]
这篇关于htaccess的301重定向问题URL变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文