需要动态 url 301 重定向的帮助

发布于 2024-09-30 13:57:20 字数 392 浏览 1 评论 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 的内容,但我想我是只是太笨了,无法弄清楚。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

原谅过去的我 2024-10-07 13:57:20

您需要使用重写模块(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] 

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] 
神也荒唐 2024-10-07 13:57:20

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]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文