htaccess动态网址重定向

时间:2016-05-20 21:30:43

标签: apache .htaccess redirect mod-rewrite

您好我想将一些动态网址重定向到某些静态网址 e.g

  • /folder/index.php?rid=321

  • http://example.com/folder/some-name-321.htm

  • /folder/index.php?rid=324

  • http://example.com/folder/some-other-name-324.htm

我试过

Redirect 301 /folder/index.php?rid=321 http ://example.com/folder/some-name-321.htm
Redirect 301 /folder/index.php?rid=324 http ://example.com/folder/some-other-324.htm

但不行。 我应该如何重定向这些网址 另外,我应该在哪里放置我的htaccess文件。 这应该在/folder/.htaccess中,或者我应该将规则放在网站根目录下的主htaccess文件中。

亲切的问候

1 个答案:

答案 0 :(得分:0)

您永远不能使用Redirect(mod-alias)指令匹配查询字符串。要操纵查询字符串,您需要在mod-rewrite

中使用/root.htaccess以下规则
RewriteEngine on


RewriteCond %{QUERY_STRING} ^rid=(.+)$
RewriteRule ^index\.php$ http://example.com/folder/some-name-%1.htm? [NC,L,R]
相关问题