Better SEF URL’s for Blogs and News – Joomla! Hack
All credit to this article goes to Ahmad from Alfy Studio. Great work!!
sh404SEF is a Joomla! extension helps you creating better SEF URLs. It’s full of features and parameters that helps you to acheieve the format you want for your Joomla! website. On July 24th 2008 the JED editors announced that sh404SEF has been added to the editors’ pick. Development cycle continued and sh404SEF became one of the must have extensions.
Bascially an article will have a URL similar to this :
With joomla built-in SEF URLs enabled the URL will be similar to :
That looks much better and more human readable. Better for SEO too! It’s effective yet very limited! We don’t have much control over the URL format. For example there is no way to hide the article-id prefixed to the title. It doesn’t tell the visitor any useful thing; why to use it?
For a lot of things we need extensions to handle SEF URLs. We need more control and more options. When using sh404SEF an article should have a URL similar to this one :
Similar to Joomla’s built-in URL but better. You can set the parameters to show/hide the section/category, use an extension like .html and more. There is a nice feature in sh404SEF helps adding a unique-id for the URL. When enabled the URL should look similar to :
That unique id is created using the date of creation (yyyy-mm-dd) added to the article id. Well that could be of great value with minor modification to modify the output to something better! Take a look at the following :
Even better, This URL tells a story! Obviously that’s a date of creation and not just a weird number! To create such a format we need to modify sh404SEF files. To get started :
- Install sh404SEF.
- Rename the file in your website root called htaccess.txt to .htaccess
- From SEO Settings in Joomla’s Global Configuration enable both Search Engine Friendly URLs andUse Apache mod_rewrite
- Go to sh404SEF control panel, make sure you’re using the extended display by clicking on the blue notice message on the right.
- Open sh404SEF configuration :
- on Main set Unique ID to Yes
- on Plugins set show-section/show-category to what suits you
- on Advanced set Rewriting mode to with .htaccess ( mod_rewrite )
- Save settings.
Lets digg into the code. Start by editing the file:
That’s the file responsible for handling the URLs for the contents. Find and delete the following code:
Save and close the file. Open:
Find this line :
Insert this code after :
We’ve only modified the last line from the code we removed from the first file.
- Moved the code to be appeneded after the /section-name/category-name/ in the URL
- The ( – ) are replaced with ( / ) using str_replace
- Removed the itemid contentElement->id
- Added the ( / ) to the end.
Save the file and now purge SEF URLs you have from the sh404SEF control panel. Try reloading your website and see how the URLs look now
If you’ve better ideas or modifications please share it! Have a nice day!