重定向问题:新类别 /文章结构 /如何摆脱文章ID?

发布于 2025-02-12 07:07:42 字数 2286 浏览 0 评论 0原文

我想,这很容易,但是无论如何,我还没有弄清楚。

将我的网站从Joomla 3迁移到Joomla 4之后,类别和文章的结构将会改变。这就是为什么我需要在.htaccess中需要一些规则将旧URL重定向到新的URL的原因。

该网站托管在Apache服务器上。

旧的URL结构看起来像这样。

< noreferrer”> https://www.mydomain.de/category/subcategory/sibcategory/item/ [aTRICLEALIAS] .html

[acrationId]是一位数字。 [ARTICLEALIAS],例如„ this-IS-Article-number-233“

应该重定向到...

https://www.mydomain.de/newcategory/newsubcategory/ [articlealias] .html

一个例子:

https://www.mydomain.de/category/subcategory/subcategory/2324-this-is-is-is-my-latest-article.html

... href =“ https://www.mydomain.de/newcategory/newsubcategory/this-is-is-my-latest-article.html” rel =“ nofollow noreferrer“> https://www.mydomain.de/newcategory/newsubcategory/newsubcategory/this-is-is-is-my-latest-article.html

它起作用。我如何摆脱文章ID?

我的最新尝试失败了...

RedirectMatch ^category/subcategory/item/([0-9]+)-(.*)$  /newcategory/newsubcategory/$1

是否有简单而优雅的解决方案?提前致谢!


更新

也许比我想象的要复杂。

主要问题是,不仅我的类别发生了变化,还改变了文章的ID。

因此,要坚持我的示例...

https://www.mydomain.de/category/subcategory/subcategory/2324-this-is-is-is-my-latest-article.html

首先变成:

https://www.mydomain.de/newcategory/newsubcategory/1223-this-is-is-my-latest-article.html.html

无论如何,JOOMLA 4可以自动放下文章ID(内部重写)用于SEO友好的URL。我激活了该功能使新URL看起来像

https://www.mydomain.de/newcategory/newsubcategory/ [articlealias] .html

[ARTICLEALIAS]保持不变。

I guess, this is an easy one but anyway, I haven't figured it out yet.

After migrating my website from Joomla 3 to Joomla 4 the structure of categories and articles will change. That's why I will need some rules in .htaccess to redirect the old urls to the new ones.

The website is hosted on an Apache server.

The old URL structure looks something like that.

https://www.mydomain.de/category/subcategory/item/[articleID]-[articleAlias].html

[articleID] is a digit.
[articleAlias], e.g. „this-is-article-number-233“

This should be redirected to...

https://www.mydomain.de/newcategory/newsubcategory/[articleAlias].html

An example:

https://www.mydomain.de/category/subcategory/item/2324-this-is-my-latest-article.html

… should be redirected to...

https://www.mydomain.de/newcategory/newsubcategory/this-is-my-latest-article.html

I've played around with RedirectMatch and Rewrite Rule but haven't been successful to make it work. How do I get rid of the article id?

My latest try failed with...

RedirectMatch ^category/subcategory/item/([0-9]+)-(.*)$  /newcategory/newsubcategory/$1

Is there a simple and elegant solution to this? Thanks in advance!


UPDATE

Maybe it's more complex than I thought it was.

Main problem is that not only my categories changed but also the ids of the articles.

So, to stick with my example...

https://www.mydomain.de/category/subcategory/item/2324-this-is-my-latest-article.html

first turns into something like:

https://www.mydomain.de/newcategory/newsubcategory/1223-this-is-my-latest-article.html

Anyway, Joomla 4 is able to drop the article id automatically (guess with an internal rewrite) for seo-friendly URLs. I activated that feature to make the new URLs look like

https://www.mydomain.de/newcategory/newsubcategory/[articleAlias].html

The [articleAlias] stays the same.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

独夜无伴 2025-02-19 07:07:42

根据您实际要求的重定向应该这样做:

RewriteEngine on
RedirectRule ^/?category/subcategory/item/[0-9]+-(.*)\.html$  /newcategory/newsubcategory/$1.html [R,L]

但是我怀疑这确实是您想要的:这完全删除了资源的数字ID。这意味着当重定向请求返回并请求新的剥离URL时,它将无法处理。那么,您如何在没有该ID的情况下内部重写该请求回到内部资源?

A redirection according to what you actually ask should be possible like that:

RewriteEngine on
RedirectRule ^/?category/subcategory/item/[0-9]+-(.*)\.html$  /newcategory/newsubcategory/$1.html [R,L]

However I doubt that this really is what you want: this completely drops the numeric ID of the resource. Which means that it won't be available for processing when the redirected request comes back requesting the new, stripped URL. How do you want to internally rewrite that request back to the internal resource then, without that ID?

峩卟喜欢 2025-02-19 07:07:42

我做了更多测试,这是解决我问题的最终解决方案:

RedirectMatch 301 ^/?category/subcategory/item/[0-9]+-(.*)\.html$ /newcategory/newsubcategory/$1.html

I made some more tests and it this is the final solution to my problem:

RedirectMatch 301 ^/?category/subcategory/item/[0-9]+-(.*)\.html$ /newcategory/newsubcategory/$1.html
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文