Home > front end >  Redirect issues: New category/article structure / How to get rid of the article id?
Redirect issues: New category/article structure / How to get rid of the article id?

Time:07-03

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.

CodePudding user response:

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?

CodePudding user response:

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

  • Related