htaccess的301重定向问题URL变量变量、重定向、问题、htaccess

由网友("脆弱制次)分享简介:如果我用这个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...

如果我用这个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]
阅读全文

相关推荐

最新文章