我正在尝试找出一个正则表达式,该表达式将在 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 文件中多长时间? Google 何时会发现新链接是好的链接?
最佳答案
您无法匹配 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]
关于php - 如何编写 .htaccess 重定向来查找所有号码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12356223/