开发者

need help for 301 redirect of dynamic urls

开发者 https://www.devze.com 2023-01-23 14:56 出处:网络
i have friendly urls active on my website, but the old ones still work, and google keeps indexing them instead of the pretty ones.

i have friendly urls active on my website, but the old ones still work, and google keeps indexing them instead of the pretty ones. The platform this is on is called prestashop.

So i need to redirect this kind of urls:

site.com/category.php?id_category=20

site.com/product.php?id_product=398

to this kind of urls:

site.com/th开发者_如何转开发e-name-of-category-with-id20

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

I've kept reading for the last 2 days about htaccess but i guess i'm just too dumb to figure it out.


You need to use the Rewrite Module (mod_rewrite):

Put in your .htaccess:

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

Or static:

RewriteEngine On
RewriteRule /catabc /category.php?id_category=20 [R,NC] 


Tx, your code looks good, but i believe it only rewrites the url? I already have the new urls, i just need to redirect to them so that i don't get duplicate pages in google.

My .htaccess contains this:

URL rewriting rules

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-([a-z]{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-([a-z]{2})/([0-9]+)-([a-zA-Z0-9-]).html(.)$ /5com/product.php?id_product=$2&isolang=$1$4 [L,E]

RewriteRule ^lang-([a-z]{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]

0

精彩评论

暂无评论...
验证码 换一张
取 消