CodeIgniter router for joomla sef urls? - codeigniter

I wish to create a front-end for joomla using CodeIgniter. I prefer to make my own front-end that reads joomla database and I had my own "framework" to accomplish this, this is because I feel that joomla front-end is too heavy for high traffic websites, because it needs to accommodate for so many user needs, at the end you would really only use a small percentage of what joomla has to offer, yet a lot of unneeded core modules load and when you have a website with 300k visits per day, every bit of resource counts. And I like joomla because of its back-end and database structure.
Anyway, I'm looking to standardize a framework for joomla front-end using CodeIgniter instead of my own messy php code, the main issue for me is the ci router. In joomla I set sef url like these:
websitex.com/
websitex.com/category.html
websitex.com/category/subcat/123-alias.html
I'm looking for a router override that would allow me to process those urls. Basically, if any of the params has a number, then its for sure an article. If it doesn't, and its not index.php then its for sure a category or subcategory (if it exists).
And if I write this:
websitex.com/123 [OR]
websitex.com/category/123-alias.html
It would display the article with id 123. At least that's how it works in joomla and its what I'm trying to achieve here.
If anyone could point me in the right direction that would be great. Thanks in advance.
ADDED:
OK #ImranQamer comment left me thinking. What if I try to do it with conventional CI router? So I tried, and came up with this:
$route['default_controller'] = "controller/index";
$route['index'] = "controller/index";
$route[':num'] = "controller/article";
$route['(:any)/:num'] = "controller/article";
$route['(:any)'] = "controller/section";
I think it may work. I've run some tests and so far so good.
First and second line, if nothing is specified OR index.suffix (index.html) is the URI, then it goes to my controller index method.
Third line, if URI is a number (eg: /123.html) then it routes to controller/article.
Fourth line needs more testing, but apparently it will grab any URI that ends with a number (or number + suffix) and route it to controller/article. Still needs another rule to let article's title alias to be put in the URI (eg: /category/123-hello.html)
And last line, will treat the URI as one of the categories/section of the joomla site. In this controller though, I'm going to need to check if submitted URI corresponds to an existing section, in which case it gets displayed, otherwise, redirected to 404.
I'm gonna test this out for a while, but looks good so far.

Related

custom routing in magento

I have multi store views in website,
The current URL for a category for the dutch store view would be;
http://www.domain.ext/nl/category.html,
http://www.domain.ext/de/category.html etc
Now I want to add country code with store code. I mean to say, I am getting country code from Users Ip and want to extend it with store code. It will be look like
If the country is set to NL the URL should now be;
http://www.domain.ext/nl_nl/category.html
If the storeview is Dutch (NL) but the country is Belgium (BE), the URL should become;
http://www.domain.ext/nl_bel/category.html
I want this only in category page. I am trying to change in match function of standard.php, but I think its role starts from controller name, please help me how can I achieve it. Any help is highly appreciated.
Are you sure you want to incorporate it into the URL like that?
I think you are going to fight a lot of Magento code to achieve it (product url, catalog url, indexing, getUrl functions and collections, rewrites).
I'm sure you have considered this and the many ways to do what you want but I think you are making work for yourself. Perhaps adding the country code as a URL query string ?c=bel or keeping it all internal to Magento by storing it in a session variable or a general function that you can call at any time eg getCustomCountryCode(). Using a cookie might be a possibility too.
If the URL is purely cosmetic then perhaps an .htaccess rewrite would suffice combined with some rel='canonical' href="http://www.domain.ext/nl_bel/category.html" on the category pages.
If you are determined to proceed then study the class Mage_Catalog_Model_Url

Joomla JRoute requiring Itemid, but providing it always is not friendly

I can see all over the internet people are talking over this.
While using JRoute::_($URL) we are forced to calculate the Itemid first and then append it to the input URL like:
JRoute::_('index.php?option=com_abc&view=xyz&id=32'.'&Itemid='.$itemid);
However, it is always desirable to calculate the Itemid automatically from within the Joomla core router from the given URL.
Since Joomla 1.5 through 3.2 today, the
JRouterSite::_buildSefRoute or the latest JRouterSite::buildSefRoute
has not changed significantly.
I can see in the codes at /libraries/cms/router/site.php file that to build the desired format sef URL it is mandatory to include Itemid=XXX in the passed URL. Otherwise
JRoute::_('index.php?option=com_abc&view=xyz&id=32');
will generate a URL something similar to
`/component/abc/?view=xyz&id=32`
unlike the desired
/our-component/?id=32
where our-component is the menu alias for the menu item pointing to
index.php?option=com_abc&view=xyz
I know that the later half ?view=xyz&id=32 can be handled by using custom router.php file per component. But the component base URL /component/abc is out of scope for that custom router.php
Please somebody advise that am I right at this thought or I am missing something big. Also advise me for how to overcome this issue.
The /component/abc is generated by the Joomla routing. Your component router.php will take care of the parameters which the component handles, so your /our-component/?id=32 may be translated into /our-component/my-id32-alias. It's not desirable that any component can tweek the basic routing on which all other components are based, and that's why you only can make-up part of the URL using router.php
Maybe you can investigate how to augment the router using a system plugin, but I think it is not what you are looking for.
http://docs.joomla.org/J2.5:Creating_a_System_Plugin_to_augment_JRouter
I've read it many times, but I find it hard to understand.

Custom profile URL for own site, been though various posts..!

I've been through a few similar posts,
Facebook Like Custom Profile URL PHP
Custom URL / Apache URL Rewriting
But its still not clear, the actual method/process is not available..
Guys , little more guidance would do a lot..
I would like to put forward the questions here:
Users should have a chance to decide what is their url, Just like in case of fb, twitter
for example: www.facebook.com/harry.inaction
I am using the linux, apache, mysql, php environment for this.
Users are identified based on their user id's which get created automatically when they join in
And I fail at the very first step, seriously I don't know get started.
Thanks
It's going to be impossible to put any details as an answer because you've got to build this system of yours and there's more than one way to do it. Design decisions will need to be made based on the way you want things to work and what you already have (they're going to have to work together in some way).
Say you've already got a system for creating users (and it sounds like you do) and you already have a system for viewing profiles. You'll need to extend this system so that you store an extra "my_vanity_url" field in your user table in your database. This field needs to be unique. When a user edits their profile, they have the option of changing this to whatever they want (limiting it to only letters and numbers and dashes for simplicity).
Next, when you display this profile, say it is via /profile.php, your code needs to check a few things.
First it needs to check how it's called, looking at $_SERVER['REQUEST_URI'] you can see either /user/some-vanity-name or /profile.php?u=1234.
If it's the latter, you need to redirect the browser, do a database lookup to see who the user with user_id 1234 is.
Pull the "my_vanity_url" column out of the database for this user and redirect the browser to /user/my_vanity_url_value (replacing my_vanity_url_value with the value of that column).
So now, if you go to http://your.domain.com/profile.php?u=1234, your browser gets redirected and the URL address bar will say http://your.domian.com/user/my_name.
Next, you need to be able to take that unique name and turn it back into the old ugly looking profile page. Two things need to happen here:
You need to extend your profile.php once more to take an optional vanity name as opposed to a user_id
You need to use mod_rewrite to internally route vanity names to /profile.php
For the first thing, you simply look for a different $_GET[] parameter instead of whatever it is for a user_id. Say it's called name: so look at $_GET['name'], see if it exists, if it does lookup the user in the user table whose vanity url name is $_GET['name']. Return the profile of that user.
For the second thing, you just need to put this in the appropriate place in your htaccess file in your document root:
RewriteEngine On
RewriteRule ^/?user/([A-Za-z0-9-]+)/?$ /profile.php?name=$1 [L]
This is just an example for how to implement something like this. It may be completely inapplicable for what you have, but it should give you an idea of what you need to do.

SEO URL Structure

Based on the following example URL structure:
mysite.com/mypage.aspx?a=red&b=green&c=blue
Pages in the application use ASP.net user controls and some of these controls build a query string. To prevent duplicate keys being created e.g. &pid=12&pid=10, I am researching methods of rewriting the URL:
a)
mysite.com/mypage.aspx/red/green/blue
b)
mysite.com/mypage.aspx?controlname=a,red|b,green|c,blue
Pages using this structure would be publishing content that I would like to get indexed and ranked - articles and products (8,000 products to start, with thousands more being added later)
My gut instinct tells me to go with the first method, but would it would be overkill to add all that infrastructure if the second method will accomplish my goal of getting pages indexed AND ranked.
So my question, looking at the pro's and con's, Google Ranking, time to implement etc. which method should I use?
Thanks!
From an SEO perspective you want to try and avoid the querystring, so getting it into the URL and a short form URL is going to get you a better "bang for the buck" on the implementation side of things.
Therefore, I'd recommend the first.
Why don't use MVC pattern, this way all your link will be SEO ready. Check here, you will find what is MVC and also some implementation in .net!
You can easily make SEO-friendly URLs with the help of Helicon Ape (the software which allows having basic Apache functionality on your IIS server). You'll need mod_rewrite I guess.
If you get interested, I can help you with the rules.
Can you explain in more detail your current architecture and what the parameters all mean? There's nothing really wrong with query strings if it's truly dynamic content. Rewriting ?a=red&b=green&c=blue to /red/green/blue is kinda pointless and it's unclear from the URL what might be on the page.
The key is to simplify as much as possible. Split the site into categories and give each "entity" one URL.
For example, if you are selling products, use one URL per product, with keywords in the URL - e.g. mysite.com/products/red-widget or mysite.com/products/12-red-widget if you need the product ID.

How to find the non-SEF URL whilst SEF is enabled (Joomla 1.5)?

I know you probably don't get many questions like this...
I am working on a component that I want to be able to deal with the non-SEF URLs whilst SEF is enabled, whether it be the built-in SEF or something like sh404sef.
Does Joomla store the ORIGINAL non-SEF URL anywhere ie. index.php?com=com_fred&view=homepage?
I've found that any SEF activated, changes the JURI::getInstance() value to the SEF equivilant.
I've also found the the $REQUEST['URI'] value does not work on all platforms/servers etc.
Thanks for any help
Get all vars from the GET/POST request into an array. At this point you may also modify the values before generating the URL string.
$getVars = JRequest::get( 'GET' );
If you really need the URL string, you can obtained with:
$newURL = http_build_query($getVars);
Hope it helps!
I came back to this code and tried again but gave me some errors, so I've reworked it partially based on the previous answer I've formulated before with this new one (working nice on Joomla! 3.4.5)
// build the JInput object
$jinput = JFactory::getApplication()->input;
// retrieve the array of values from the request (stored in the application environment) to form the query
$uriQuery = $jinput->getArray();
// build the the query as a string
echo 'index.php?' . JUri::buildQuery($uriQuery);
Joomla! API Docs: JInput - JUri
PREVIOUS ANSWER:
Googling around I found this:
<?php
// "unparse" the Joomla SEF url to get the internal joomla URL
JURI::current();// It's very strange, but without this line at least Joomla 3 fails to fulfill the task
$router =& JSite::getRouter();// get router
$query = $router->parse(JURI::getInstance()); // Get the real joomla query as an array - parse current joomla link
$url = 'index.php?'.JURI::getInstance()->buildQuery($query);
?>
I've tested it with Joomla! 3.4.4 and its working fine! Dunno if it can work with 1.5
You can use JRequest::get(true) to get an array of all the query parameters from the URL. A quick note though, I haven't checked it enough to know if it only returns GET parameters or it does all REQUEST parameters (which I think is more likely). It might, however, help with what you're looking for.
For menu items, it's stored in the 'jos_menu' table, in the 'link' column (but the itemid is not in this string - it's the 'id' column).
For anything else, it's probably not stored in the database, but can normally be worked out pretty easily, especially with core components. It can be a little bit of a pain with third party components, but you can look through the MVC architecture of most components to figure it out.
Otherwise, you could always turn off SEF on your dev site/create a dev site for this.
Is there a specific component that you're curious about?
The link that I posted here:
Joomla URLs: An article doesn't have a pretty URL by itself?
provides a very good "crash course" for URLs in Joomla 1.5
You don't have to do anything special for non-SEF URLs. Even if you have SEF URLs turned on, Joomla will still display the correct page if someone access the site with a non-SEF URL. The portion of your component that handles SEF URLs, the router, only tells Joomla how to use the URL information to determine what to display. When presented with a non-SEF URL Joomla just parses the query string as it normally would.
For any given component, the URL is built like this -
index.php?option=com_name&view=XXXX&id=1111&Itemid=11111
option is the name of the component
view is of course which view to display
id is the id of the particular content item
itemid is the menu item it used to determine module/template assignment

Resources