I have a lot of simpler rules working on this site so I know mod_rewrite is working. I just can't figure out how to create a rule for this situation. I'm using Joomla CMS and one component in particular is generating awful URLs that duplicate other (pretty) URLs on the site. There is a consistent pattern so I can rewrite the URLs but this is way out of my league for using regular expressions.
The bad URLs look like this:
/component/content/article/111-category-name/111-article-name.html?directory=2
(the "111
" parts are slugs generated to give unique IDs to the category and article portion of the URL, so these numbers are unique per URL, and the directory=2
changes depending on the number ID of the directory being browsed)
The good URLs (already on the site, generated by core Joomla SEF) look like this:
/category-name/article-name.html
I know I need to detect the bad URLs, then rewrite to remove those slug IDs and the trailing query string. I've tried for an embarrassing amount of time to work it out and I don't think I'm even remotely close.
My eternal gratitude to a mod_rewrite/regular expressions guru who can break this down for me. Thanks! -Kelly