Remove id article from url. Htaccess code not work Topic is solved

Discuss Search Engine Optimization in relation to Joomla! 4.x. This forum will also have discussions on SEF/SEO Joomla! 4.x extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
gymvago
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 125
Joined: Thu Aug 18, 2011 12:49 am
Contact:

Remove id article from url. Htaccess code not work

Post by gymvago » Sun Sep 18, 2022 3:15 pm

Hello. I am trying to upgrade my joomla 3 webs to joomla 4, and to take advantage of this opportunity to remove article id from the url. It is a lot of urls, so I think it is more simple to use an htaccess code than using the redirect component.

I have tried this code that I have seen in this forum, but it doesn't work for me:

Code: Select all

RewriteCond %{REQUEST_URI} [0-9]+-
RewriteRule ^(.*)/[0-9]+-(.*)$ $1/$2 [R=301,L]
It rewrites me the complete url, like this:

Code: Select all

https://myweb.com/category/14-my-article
https://myweb.com/var/www/myweb.com/public_html/category/my-article
What is the bug?

gymvago
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 125
Joined: Thu Aug 18, 2011 12:49 am
Contact:

Re: Remove id article from url. Htaccess code not work

Post by gymvago » Fri Sep 23, 2022 10:56 am

I answer myself. To avoid rewriting the entire path (var/www/), a slash was missing. The correct htaccess code is:

Code: Select all

RewriteCond %{REQUEST_URI} [0-9]+-
RewriteRule ^(.*)/[0-9]+-(.*)$ /$1/$2 [R=301,L]
However, now I have a new problem. When I have an article with a title beginig with a number, for example: "10 recommended TV models", thats code also remove number "10" and url is broken.

Is there any way to differentiate the ID added by the system from the title number of an article? I understand that this may not be possible.

For small webs, I suppose that it could be solved easily making the redirections one by one, but for webs with more than 500 articles, this does not seem feasible. is it true?


Post Reply

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 4.x”