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 :
“http://localhost/index.php?option=com_content&view=article&id=19”
With joomla built-in SEF URLs enabled the URL will be similar to :
“http://localhost/category-name/19-article-title”
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 :
“http://localhost/category-name/article-title.html”
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 :
http://localhost/2008081219/category-name/article-title.html”
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 :
“http://localhost/category-name/2008/08/12/article-title.html”
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:
/components/com_sh404sef/sef_ext/com_content.php
That’s the file responsible for handling the URLs for the contents. Find and delete the following code:
Save and close the file. Open:
/components/com_sh404sef/sef_ext.php
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!