我的网站上有友好的网址,但旧网站仍在使用,谷歌一直在索引它们而不是漂亮的网址。 这个平台叫做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的最近2天我一直在阅读,但我想我太傻了,无法弄明白。
答案 0 :(得分: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]
答案 1 :(得分:0)
Tx,您的代码看起来不错,但我相信它只会重写网址? 我已经有了新的网址,我只需要重定向到它们,这样我就不会在谷歌中获得重复的网页。
我的.htaccess包含这个:
RewriteRule ^([a-z0-9] +) - ([a-z0-9] +)( - [_ a-zA-Z0-9 - ] *)/([_ a-zA-Z0-9 - ] *)。jpg $ /5com/img/p/$1-$2$3.jpg [L,E]
RewriteRule ^([0-9] +) - ([0-9] +)/([_ a-zA-Z0-9 - ] *)。jpg $ / 5com / img / p / $ 1- $ 2。 jpg [L,E]
RewriteRule ^([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]
RewriteRule ^([a-zA-Z0-9 - ] )/([0-9] +) - ([a-zA-Z0-9 - ] )。html(。 *)$ /5com/product.php?id_product=$2$4 [L,E]
RewriteRule ^([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]
RewriteRule ^ lang - ([a-z] {2})/(。*)$ / 5com / $ 2?isolang = $ 1 [QSA,L,E]