基本301重定向不起作用

时间:2012-10-29 17:29:32

标签: .htaccess

我正在尝试将一些旧博客帖子重定向到新帖子。这是我编写的htaccess并放在根目录中。请记住,该网站现在在Linux服务器上,而不是Windows。

redirect 301 /public/recipesdetl.aspx?id=1888 http://www.mysite.com/recipes/
redirect 301 /public/recipesdetl.aspx?id=2025 http://www.mysite.com/recipes/?p=405
redirect 301 /public/recipesdetl.aspx?id=2682 http://www.mysite.com/recipes/?p=549
redirect 301 /public/recipesdetl.aspx?id=2152 http://www.mysite.com/recipes/?p=309
redirect 301 /public/recipesdetl.aspx?id=1398 http://www.mysite.com/recipes/?p=817
redirect 301 /public/recipesdetl.aspx?id=1908 http://www.mysite.com/recipes/?p=155
redirect 301 /public/recipesdetl.aspx?id=2162 http://www.mysite.com/recipes/?p=317
redirect 301 /public/recipesdetl.aspx?id=1889 http://www.mysite.com/recipes/?p=145
redirect 301 /public/recipesdetl.aspx?id=1951 http://www.mysite.com/recipes/?p=808
redirect 301 /public/recipesdetl.aspx?id=2032 http://www.mysite.com/recipes/?p=238
redirect 301 /public/recipesdetl.aspx?id=2101 http://www.mysite.com/recipes/?p=269
redirect 301 /public/recipesdetl.aspx?id=2147 http://www.mysite.com/recipes/?p=304
redirect 301 /public/recipesdetl.aspx?id=2563 http://www.mysite.com/recipes/?p=449
redirect 301 /public/recipesdetl.aspx?id=2043 http://www.mysite.com/recipes/?p=243
redirect 301 /public/recipesdetl.aspx?id=2224 http://www.mysite.com/recipes/?p=361
redirect 301 /public/recipesdetl.aspx?id=2151 http://www.mysite.com/recipes/?p=308

1 个答案:

答案 0 :(得分:0)

您可以在Redirect语句的第一个URI路径中包含查询字符串,您需要使用mod_rewrite的%{QUERY_STRING}变量:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^id=1888$
RewriteRule ^/?public/recipesdetl.aspx$ http://www.mysite.com/recipes/ [L,R=301]

RewriteCond %{QUERY_STRING} ^id=2025$
RewriteRule ^/?public/recipesdetl.aspx$ http://www.mysite.com/recipes/?p=405 [L,R=301]

RewriteCond %{QUERY_STRING} ^id=2682$
RewriteRule ^/?public/recipesdetl.aspx$ http://www.mysite.com/recipes/?p=549 [L,R=301]

RewriteCond %{QUERY_STRING} ^id=2152$
RewriteRule ^/?public/recipesdetl.aspx$ http://www.mysite.com/recipes/?p=309 [L,R=301]