在htaccess中将动态URL重定向到新的动态URL

时间:2015-01-26 18:19:29

标签: apache .htaccess mod-rewrite redirect dynamic

我正在撞墙。我创建了一个网站的更新版本,我有各种动态页面,通过PHP提供。旧页面通过htaccess对它们进行了以下重写:

REWRITE之前的旧网址:

/directorio_hoteles/ean/hotel.php?cou=$1&hn=$2&city2=$3

REWRITE后的旧网址:

/directorio_hoteles/Mexico/hotel336813/Villa_Mercedes_Petit_Hotel.htm

这里是如何在原始的HTACCESS中编码:

RewriteRule ^([^/]*)/hotel([^/]*)/([^/]*)\.htm$ ean/hotel.php?cou=$1&hn=$2&city2=$3 [L]

我知道这种原始格式并不是实现此目的的最佳方式,但这是我必须使用的内容,并且动态网址已经在谷歌中编入索引。所以我需要采用上面已经重写的url并将其重定向(301)为新的动态格式:

REWRITE之前的新网址:

directorio-hoteles/index.php?p=hotel-page&a=$1&b=$2&c=$3

REWRITE后的新网址:

directorio-hoteles/hotel/Mexico/Villa_Mercedes_Petit_Hotel/336813

这是如何在新的HTACCESS文件中编码:

RewriteRule    ^directorio-hoteles/hotel/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$     directorio-hoteles/index.php?p=hotel-page&a=$1&b=$2&c=$3   [NC,L]

所以我无法理解如何解决这个问题:

/directorio_hoteles/Mexico/hotel336813/Villa_Mercedes_Petit_Hotel.htm

重定向到此:

directorio-hoteles/hotel/Mexico/Villa_Mercedes_Petit_Hotel/336813

任何帮助都将被超越赞赏。提前感谢您解决此问题的任何尝试。

1 个答案:

答案 0 :(得分:0)

您可以在DOCUMENT_ROOT/.htaccess文件中将此规则用作第一条规则

RewriteEngine On

RewriteRule ^(directorio_hoteles)/([^/]+)/(hotel)([^/]+)/([^.]+)\.htm$ /$1/$3/$2/$5/$4 [L,NC,NE,R=302]
相关问题