修改mod_rewrite后的链接


adapting links after mod_rewrite

在Stack Overflow的帮助下,我设法更改了我的链接,使它们对用户和搜索引擎更友好。此URL http://www.showcase.zz.mu/oferta.php?tip=Club&nume=Goblin&localitate=Bucuresti&judet=Bucuresti&id=52138700c4d7c已更改为此URL http://showcase.zz.mu/oferta/Club-Goblin-Bucuresti-Bucuresti-52138700c4d7c.php。如果我尝试手动访问新的URL,它会正常工作。然而,在我的搜索页面上,生成的链接仍然是旧的,访问动态生成的页面时URL保持不变。

这是我的.haccess内容:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteRule ^oferta/([^-]*)-([^-]*)-([^-]*)-([^-]*)-([^-]*)'.php$ /oferta.php?tip=$1&nume=$2&localitate=$3&judet=$4&id=$5 [NC,L,QSA]

这是在PHP中生成链接的代码:

echo "<a href='oferta.php?tip={$result['tip_locatie']}&nume={$result['denumire_locatie']}&localitate={$result['localitate']}&judet={$result['judet']}&id={$result['id_oferta']}'><p style='margin-top: -5px;'>View page</p></a>";

如果你想知道$result是什么:

$result = mysql_fetch_array( $resulta )
$resulta = mysql_query($query)

如果你还有什么需要看的,请告诉我。在降低评分之前也请告诉我,这样我就可以编辑我的问题了。非常感谢。

您需要一个额外的规则来进行从旧URL到新URL的外部重定向。你的代码是这样的:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}'s/+oferta'.php'?tip=([^&]*)&nume=([^&]*)&localitate=([^&]*)&judet=([^&]*)&id=([^'s&]*) [NC]
RewriteRule ^ /oferta/%1-%2-%3-%4-%5.php? [R=301,L]
RewriteRule ^oferta/([^-]*)-([^-]*)-([^-]*)-([^-]*)-([^-]*)'.php$ /oferta.php?tip=$1&nume=$2&localitate=$3&judet=$4&id=$5 [NC,L,QSA]