mod_rewrite的适应后链接 [英] adapting links after mod_rewrite

查看:138
本文介绍了mod_rewrite的适应后链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用别人的,我设法改变我的链接,使他们更方便用户和搜索引擎友好的帮助下,从堆栈溢出。此网址<$c$c>http://www.showcase.zz.mu/oferta.php?tip=Club&nume=Goblin&localitate=Bucuresti&judet=Bucuresti&id=52138700c4d7c得到了改变这个网址 http://showcase.zz.mu/oferta/Club-Goblin-Bucuresti-Bucuresti-52​​138700c4d7c.php 。如果我尝试访问新的URL手动它的工作原理,因为它应该。但是在我搜索页面的生成的链接仍然是旧的URL访问动态生成的页面时保持不变。

With the help of someone from Stack Overflow I managed to change my links so that they are more user and search engine friendly. This URL http://www.showcase.zz.mu/oferta.php?tip=Club&nume=Goblin&localitate=Bucuresti&judet=Bucuresti&id=52138700c4d7c got changed to this URL http://showcase.zz.mu/oferta/Club-Goblin-Bucuresti-Bucuresti-52138700c4d7c.php. If I try to access the new URL manually it works as it should. However on my search page the generated link is still the old one and the URL stays the same when accessing the dynamic generated page.

这是我.htacess内容:

This is my .htacess content:

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]

这是在code产生在PHP中的链接:

This is the code that generates the links in 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>";

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

In case you're wondering what $result is:

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

如果有什么更多的,你需要看到让我知道。也让downrating,这样我可以修改我的问题之前,我知道。谢谢!

If there's anything more that you need to see let me know. Also let me know before downrating so that I can edit my question. Thank you!

推荐答案

您需要从旧的URL到新的URL外部重定向一个额外的规则。让你的code是这样的:

You need an additional rule for external redirect from old URL to new URL. Have your code like this:

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]

这篇关于mod_rewrite的适应后链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆