abr
abr

Reputation: 103

Codeigniter shorten urls

Is it possible to create such urls in codeigniter? http://site.com/shorturl/

Where shorturl isn't a physical controller file, but a variable.

I expect the algorythm for parsing url query to be like this: 1) Search for physical controller file. If exists, do standard codeigniter routine. If not 2) Try to load special controller file, where "shorturl" is a variable. Do further stuff inside that controller.

Thanks in advance

Upvotes: 0

Views: 912

Answers (1)

cchana
cchana

Reputation: 5000

The previous answer seems quite good, but thought I'd share what I'd though of.

If you set your 404_override to point to a controller you have set up as follows:

$route['404_override'] = 'welcome/short';

Any URL that doesn't exist (any short URL for example) would get sent there, where you could do the following to check the value:

public function short() {

    $shortCode = $this->uri->segment(1);

}

That would give you the value you need to check. If all is well, do the redirect, if the code doesn't exist, you can then use the show_404 method to actually show the 404 page.

Upvotes: 1

Related Questions