如何编写.htaccess重定向来查找所有数字


How can I write a .htaccess redirect to find all numbers?

我正试图找出一个正则表达式,它可以在URL中找到一些数字,并在我重定向到的URL中使用它们。

Redirect 301 /page.php?id=95485666 http://test.com/profile/info/id/95485666

我在想也许

Redirect 301 /page.php?id=([0-9]+) http://test.com/profile/info/id/$1

但似乎不起作用

此外,如果我进行301重定向,我必须将代码保存在.htaccess文件中多长时间?谷歌什么时候才能发现新链接是好的?

Redirect指令中(在RedirectMatch/RewriteRule中也一样),不能与查询字符串匹配。您需要使用mod_rewrite的%{QUERY_STRING} var:

RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)id=([0-9]+)($|&)
RewriteRule ^/?page'.php$ http://test.com/profile/info/id/%2? [L,R=301]

我猜语法不正确。试试这个:

RewriteRule ^page.php?id=([0-9]+)  http://test.com/profile/info/id/$1  [R=301,L]