The examples on this site are currently tested to work on Phalcon V3.4 and Phalcon Devtools V3.2 Some issues may arise when using later versions.

Please get in touch or post a comment below the post if you encounter a problem.

URL Problems

There are a number of acknowledged problems URLs.  A typical PHP URL make take the form

http://localhost/index.php?action=showStudent&name=Joe%20%Bloggs

Non-expert web users find this complex and off putting. In addition, there is the eternal problem of dead links. The term 404 has entered the regular lexicon as a slang term to refer to someone or something which is not found.

As early as 1993 Tim Berners Lee foresaw a problem with URLs. Berners Lee hoped that, in time, URLs would be replaced by URNs. URN stands for Unform Resource Name. URNs are supposed to be uniform in space and time. This means that no matter when you visit a URN it will never be broken. Of course it's difficult to guarantee this but search engines storing hashed copies of pages can allieviate the problem.

Whether it was the original plan for the way the web would work or not URLs became a crucial part of the vernacular of the web. Whenever anyone wants to share information contained in a webpage the share/post/email/tweet the URL. Domain names became crucial for organisation's branding.

URL Complexity

As it became apparent that URLs could also be important for search engine ranking people began to try and encode more and more information into the URL. As a result URLs have become more unwieldy, with way to much information encoded into them. This not only makes them harder to remember and share but it also makes it more difficult for users to discern the identity of the organisation hosting the page. 

Linkrot

Another problem with URLs is linkrot. Linkrot (also called link decay) describes the rate at which web links become unavailable. For various reasons links that once worked become dead. This could be because the website no longer exists, or because the article or post was removed. Ironically, it may even be because the website decided to change the URL to make it more search engine friendly. It is estimated that typical "half life" for a link is between two and five years. 

This continued dying of links represents a systemic threat to the health of the web. This problem has long been identified and a number of organisations, including google, are continually working on ways to phase out URLs. With URLs being so ingrained it's a challenging problem that is unlikely to be fully resolved any time soon.

URL Information Overload

In addition to the URLs becoming naturally complex with more parameters and name-value pairs being passed to web pages to make them function the length and complexity of links is also growing due to their perceived importance to search ranking algorithms. URL Keyword stuffing is the process of including keywords in URLs in the hope that the web-page associated will get a higher search ranking for those search terms. This behaviour has a further negative effect on link complexity and link rot.

URL Security

All of this URL complexity ultimately makes it easier for hackers to confuse web users, redirecting them to phishing sites and malware downloads. Modern mobile devices often aren't big enough to display the entire URL. It's a relatively easy thing for a hacker to make a URL appear to link to a legitimate organisation where really the link is routing to a phishing site with the goal of harvesting users valuable information. Naive users of poorly designed sites can even send on URLs that have Usernames and Passwords embedded. The bottom line is that hackers love URLs they are very easy to exploit.

The Solutions

Bootstrap page and mod-rewrite

Without having added any specific routes or functionality the MVC framework approach by using Controllers will actions and passing parameters in the URL we have already massively tidied up the URL from how it would look in a traditional PHP application. 

http://localhost/index.php?action=showStudent&name=Joe%20%Bloggs

Now will read something like

http://localhost/student/show/5

Where 5 is the student id. This tidying up of the URL has been achieved by a combinationo of mod-rewrite and a bootstrap page(not twitter Bootstrap - "bootstrapping" is the term traditionally given to the steps a system goes through when strarting up). In the case of Phalcon this bootstrap page is /public/index.php. The bootstrap page starts up the various services associated with phalcon. Mod-rewrite is the rewrite engine which is part of the Apache web server. Mod-rewrite is based on the PCRE standard regular expressions. Mod-rewrite is very powerful and useful but there is a learning curve associated with it. Thankfully routing makes it easier for developers to control the URLs and the information contained within them.

Url Shortening

As urls have become too long to type people have turned to url shorteners. URL shortners such as TinyURL are third party services which offer a range of different features - the main one being they make the URL shorter. Often nothing at all about the organistion or site to which you are being directed can be discerned from a shortened URL they at least have the advantage of being quicker to type in and take up less space. While shortners make the URL less readable and less memorable others have branding and analytics features. One of the things that original boosted the demand for these services was twitter which allowed for so few characters that you couldn't waste them on a URL. This reason for being has largely disappeared with twitter not including the link characters in the measurement of a tweet and also allowing for longer tweets. URL shortners live on and offer useful and varied other services but they're not as prevalent as they were a few years ago. 

Possible Future moves to Phase out URLs

In 2014 google piloted a feature for chrome called "origin chip" which meant, among other things, that only the hostname part of the URL would be visible to browser users. The feature was put on the backburner amid security concerns. In 2018 a number of articles have emerged pointing out that google is working on having another go at changing how URLs work or even, ultimately, getting rid of URLs https://www.wired.com/story/google-wants-to-kill-the-url/. It's not entirely clear that google, so far, have a solution to the problem. URLs are such an intrinsic part of the web that it's very difficult to even change how they work never mind remove them. But Google Chrome is by far the biggest player in this space so if Google says they are going to address the problem it's likely they could move things along.

Pretty URLs

A standard PHP URL might read something like

http://localhost/index.php?action=showStudent&name=Joe%20%Bloggs

The inclusion of question marks, ampersands and percentage symbols does nothing to help URLs become more digestible by users or search engines. Thankfully, Modern MVC framework give designers and programmers greater control over URLs. "Routing" allows pretty much any URL to be represented in a way that is more palatable to users and search engines alike. With the use of routing the URL above is more likely to read something like:

http://localhost/showStudentNamed/joe-bloggs

This type of URL called pretty URLs or sometimes called semantic URLs is much more readily understandable by both users and search engines. Using routing means application designers can design their links according to their desired search terms. Given that the text of a link is will no longer be determined merely by the names of pages and actions this should mean that the links survive longer leading to an overall reduction in link rot. Websites, their users and the health of the web overall should all benefit from a greater adoption of routing techniques.