需要动态 url 301 重定向的帮助
我的网站上有活跃的友好网址,但旧的网址仍然有效,并且谷歌不断对它们而不是漂亮的网址进行索引。 这个平台叫做 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 的内容,但我想我是只是太笨了,无法弄清楚。
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/the-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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用重写模块(mod_rewrite):
放入您的.htaccess:
或静态:
You need to use the Rewrite Module (mod_rewrite):
Put in your .htaccess:
Or static:
Tx,你的代码看起来不错,但我相信它只是重写了网址?
我已经有了新的网址,我只需要重定向到它们,这样我就不会在谷歌中得到重复的页面。
我的 .htaccess 包含以下内容:
URL重写规则
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-]< em>)(.)$ /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-([az]{2})/(.*)$ /5com/$2?isolang=$1 [QSA,L,E]
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]