繁体   English   中英

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

[英]Redirecting dynamic url to new dynamic url in htaccess

我的头撞在墙上。 我已经创建了网站的更新版本,并且有通过PHP提供的各种动态页面。 通过htaccess对旧页面进行以下重写:

重写前的旧网址:

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

重写后的旧网址:

/directorio_hoteles/Mexico/hotel336813/Villa_Mercedes_Petit_Hotel.htm

这里是如何在原始成功中进行编码的:

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

我知道这种原始格式并不是实现此目的的最佳方法,但这是我必须使用的格式,而且动态url已经在google中建立了索引。 因此,我需要使用上面已经重写的网址,并将其重定向(301)为新的动态格式,即:

重写之前的新网址:

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

重写后的新网址:

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

任何帮助将不胜感激。 预先感谢您为解决此问题所做的任何尝试。

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

RewriteEngine On

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM