简体   繁体   中英

adapting links after mod_rewrite

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.

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]

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)

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!

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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