301将旧动态URL重定向到新的动态URL

时间:2015-01-21 07:54:46

标签: .htaccess mod-rewrite redirect

我的.htaccess如下所示

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^condos-([^-]*)-([^-]*)\.html$ /fm
/cond_new?r_id=$1&location=$2 [L]

以上网址是我以前的动态网址http://localhost/fm/condos-2-delhi.html

我的新动态网址为http://localhost/fm/delhi/2/condos,而.htaccess低于模式

RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ /fm
/condo_new?location=$1&r_id=$2&name=$3 [L]

现在我希望模式http://localhost/fm/condos-2-delhi.html的所有网址都重定向到http://localhost/fm/delhi/2/flavor并重定向301。 味道是产品的名称。

我尝试如下但没有成功

RedirectMatch 301 ^condos-([^-]*)-([^-]*)\.html$ ^([^/.]+)/([^/.]+)
/([^/.]+)/?$

1 个答案:

答案 0 :(得分:1)

您可以在/fm/.htaccess

中使用此规则
RewriteRule ^(condos)-([^-]+)-([^-]+)\.html$ /fm/$3/$2/$1 [L,NC,R=301]

确保这是RewriteEngine On下面的第一条规则。