0

我的网站上有活跃的友好网址,但旧网址仍然有效,谷歌一直在索引它们而不是漂亮的。它所在的平台称为 prestashop。

所以我需要重定向这种网址:

site.com/category.php?id_category=20

site.com/product.php?id_product=398

到这种网址:

site.com/the-name-of-category-with-id20

site.com/the-name-of-category-with-id20/the-name-of-product-with-id398.html

在过去的两天里,我一直在阅读有关 htaccess 的内容,但我想我太笨了,无法弄清楚。

4

2 回答 2

1

您需要使用重写模块(mod_rewrite):

放入您的 .htaccess:

RewriteEngine On 
RewriteRule /the-name-of-category-with-id([0-9]+) /category.php?id_category=$1 [R,NC] 

或静态:

RewriteEngine On
RewriteRule /catabc /category.php?id_category=20 [R,NC] 
于 2010-11-06T13:22:47.123 回答
0

Tx,您的代码看起来不错,但我相信它只会重写 url?我已经有了新的 url,我只需要重定向到它们,这样我就不会在 google 中获得重复的页面。

我的 .htaccess 包含以下内容:

URL重写规则

重写规则 ^([a-z0-9]+)-([a-z0-9]+)(-[_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]* ).jpg$ /5com/img/p/$1-$2$3.jpg [L,E]

重写规则 ^([0-9]+)-([0-9]+)/([_a-zA-Z0-9-]*).jpg$ /5com/img/p/$1-$2.jpg [L ,E]

重写规则 ^([0-9]+)(-[_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*).jpg$ /5com/img/c/$1$2 .jpg [L,E]

RewriteRule ^lang-([az]{2})/([a-zA-Z0-9-] )/([0-9]+)-([a-zA-Z0-9-] ).html( .*)$ /5com/product.php?id_product=$3&isolang=$1$5 [L,E]

RewriteRule ^lang-([az]{2})/([0-9]+)-([a-zA-Z0-9-] ).html(. )$ /5com/product.php?id_product=$2 &isolang=$1$4 [L,E]

RewriteRule ^lang-([az]{2})/([0-9]+)-([a-zA-Z0-9-] )(. )$ /5com/category.php?id_category=$2&isolang= $1 [QSA,L,E]

重写规则 ^([a-zA-Z0-9-] )/([0-9]+)-([a-zA-Z0-9-] ).html(.*)$ /5com/product.php? id_product=$2$4 [L,E]

重写规则 ^([0-9]+)-([a-zA-Z0-9-] ).html(. )$ /5com/product.php?id_product=$1$3 [L,E]

RewriteRule ^([0-9]+)-([a-zA-Z0-9-] )(. )$ /5com/category.php?id_category=$1 [QSA,L,E]

RewriteRule ^content/([0-9]+)-([a-zA-Z0-9-] )(. )$ /5com/cms.php?id_cms=$1 [QSA,L,E]

RewriteRule ^([0-9]+)__([a-zA-Z0-9-] )(. )$ /5com/supplier.php?id_supplier=$1$3 [QSA,L,E]

RewriteRule ^([0-9]+)_([a-zA-Z0-9-] )(. )$ /5com/manufacturer.php?id_manufacturer=$1$3 [QSA,L,E]

重写规则 ^lang-([az]{2})/(.*)$ /5com/$2?isolang=$1 [QSA,L,E]

于 2010-11-06T15:07:26.227 回答