0

我正在尝试重定向

http://www.example.com/component/plant/?view=plant&plant-id=477http://www.example.com/component/plant/?view=plant&id=477

我需要最后从网址中删除单词植物。我试过了,但没有得到正确的结果

RewriteEngine On
# Capture (\d+) into %1
RewriteCond %{QUERY_STRING} plant-id=(\d+) [NC]
# And rewrite (redirect) into id=%1
RewriteRule ^(.*)$ /component/plant/?view=plant&$1?id=%1 [L,R=301]

但这对我来说效果不佳。

4

2 回答 2

1

这应该适合你:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(view=plant)&plant-id=([0-9]*)(?:&|$) [NC]
RewriteRule ^(component/plant)/?$ /$1/?%1&id=%2 [L,NC,R=301]
于 2013-11-02T09:06:45.097 回答
0

最简单的 .htaccess 重定向:

Redirect 301 /component/plant/?view=plant&plant-id=477 /component/plant/?view=plant&id=477

或 php 重定向:

<?php
    header( 'Location: http://www.example.com/component/plant/?view=plant&id=477' ) ;
?>
于 2013-11-02T08:00:09.927 回答