path as param in fat free framework - php

while routing in fat free framework, i need a URL as param
but i don't know how.
if i route to
GET /get-links/#url
#url can be any string WITHOUT /.
that means, if i open /get-links/www.muv.com it works. but if i open /get-links/www.muv.com/homepage.html the routing will not work.
i also tried GET /get-links/* - the routing works, meaning my function gets called.
but then how to get the #url (www.muv.com/homepage.html)?
and the next problem is: how to enter http://www.muv.com/homepage.html as #url

You may want to escape the characters that give you problems. For URLs there is a standard for this. PHP has rawurlencode. Maybe this helps.

Related

.htaccess How to routing from /a/b/c.php to /a/c.api

I am very newbie on .htaccess and such a things
i really need to route my files
when accessed :
http://blabla/api/bla.api
but the real file source is
http://blabla/api/files/test/test.php
if i use Fat-Free-Framework, that might be possible.
but how to implements it on .htaccess ??
Thanks!
i think that you're mixing up some stuff ...
.htaccess file cannot real route an uri . You can redirect, rewrite, ... but real routing is not an option, you just make your URI 'nicer' to read
A router (usually) will talk to controller witch will fetch, calculate, do stuff and pass the result to a view that will generate your page with the info passed from controller.
But anyway, here are some code snippets for redirecting with .htaccess or/and follow this tutorial for .htaccess redirects and easy php example that gives you more power to supports more complex logic.

seo friendly url for codeigniter

We have a social networking web site for students. Our url looks like this domain.com/student/145236 where 145236 is the roll number. We now have an option of doing something like this domain.com/student/145236/student-name but since google / search engines would prefer domain.com/student-name/student/145236 we would like to do like this, but we are unable to do it, we tried doing this using routes $route['(:any)/student/(:num)'] = 'student/$1'; but it shows 404 page, any help would be grateful :)
This should be work for you:
$route['(:any)/student/(:num)'] = 'student/yourfunction/$1/$2'; 
Here $1 is for ist param (:any) and
$2 is for second param (:num) .
For getting values from the URL inside the student controller you can use CI Segments.

Codeigniter dynamic variable routing

I am looking to dynamically re-route urls based on a parameter within the uri segment. For example if I have the following url:
domain.com/account/message/action/view
How could I go about creating a route that checked to see if the uri contained "action" and if so re-route to the value of the function + '_' + value of action?
domain.com/account/message_view
I've been reading through the routes documentation provided by ellislab and am still not quite sure how to go about doing something like this or if it would be better to use server rewrite rule? Any information greatly appreciated!
You would likely want to use the regular expressions availability in routes. Something along the lines of:
$route['([a-z]+)/action/([a-z]+)'] = "$1_$2";
Of course, that may not be exactly what you are looking for, but it should get you started.

Quick help - CodeIgniter routing

Need a quick hand on setting custom route for my project.
the code works without any reoute definition as
http://myblog.local/posts/categories/show/1
but I want to access it as following;
http://myblog.local/posts/1
and I've changed my route as following;
$route['posts/(:any)'] = 'posts/categories/show/$3';
But my route declaration seems not working, please help me where i am doing the mistake
$route['posts/(:num)'] = 'posts/categories/show/$1';
Because you have only 1 segment (the first) to match: $1
And the segment must be a number: (:num)
(:any) will work too.
$route['posts/(:num)'] = 'posts/categories/show/$1';
also in config file
make it blank
$config['index_page']='';
hope this might work.

Redirect & Route wildcard URL - with underscores to hyphens

I'm using CodeIgniter and I needed to redirect several urls with underscores to their equivalent with hyphens.
/some-controller --> /some_controller
I've partially solved this issue by tweaking the config/routes.php file.
The thing is :
How would I expand that to a Controller's function WITH a parameter.
Let's say I've got a controller some_controller (some-controller redirects to some_controller) and a function func in it (optionally taking a param).
$route['some-controller'] = 'some_controller';
$route['some-controller/func'] = 'some_controller/func';
This works. But, what if I have some-controller/func/someparam. (and someparam can be anything).
How could this redirect be implemented?
Basically what I need is a redirection from :
some-controller/func/*
to
some_controller/func/*
Any ideas?
Hint :
I don't need anything complicated like this one (
How to replace underscores in codeigniter url with dashes? ).
Hadn't searched enough - I admit it (it's one of those issues that always seem more complicated than they should be) :
http://codeigniter.com/user_guide/general/routing.html
$route['some-controller/func/(:any)'] = "some_controller/func/$1";
Or you could use (:num), if what you're expecting is a number...

Categories