I'm trying to make this work. I want my routing to behave like this:
when I type URL ie. example.com/api/getpage/http://smth.com I want to retrieve in my action id parameter with http://smth.com value.
My routing for this case looks like this right now:
Route::set('api', 'api/<action>/<id>')
->defaults(array(
'controller' => 'api',
'action' => 'index'
));
And what's in action:
public function action_getpage()
{
$obj = $this->scrape($this->request->query('id'));
$this->response->body(json_encode($obj));
}
Now URL like this example.com/api/getpage?id=http://smth.com works like a charm, but I don't want it that way. Is there any way to achieve that goal? Thanks in advance for all suggestions.
The problem is you can't use slashes within a url segment (except in get parameters). This has nothing to do with kohana routing but how your web server handles it. The only way around it would be to replace he slashes with something else. You'd also encounter issues if the url you pass as the final segment had get parameters on the end of it, the question mark would be cause it to be treated as get parameters of your main url, not the final segments.
Another option would be to base64 encode the final url segment then decode it inside your controller. This would get rid of any slashes and question marks. Php has simple base64_encode and base64_decode functions. The only downside is tha portion of the url will look like an arbitrary garbled string. http://php.net/manual/en/function.base64-encode.php
Related
i need help with my code:
Im including pages in index.php like:
if(isset($_GET['xx'])
{
// include('yy/'.$_GET['xx'].'.php');
}
and now in the file page.php i wanna use get parameters like from and to.
i use htaccess for short url
RewriteRule ^([a-z]*)$ ./main.php?xx=$1
So i get this url in final:
index.php?xx=page?from=a&to=b
When i print_r($_GET) i got only first parameter xx
$_POST parameter works fine, but i need it with $_GET.
Look at the URL:
index.php?xx=page?from=a&to=b
It should be
index.php?xx=page&from=a&to=b
You put ? in there twice instead of a &
Solved!
by misorude
By specifying your own query string in the replacement, you are
discarding the original one - this is default behavior with
mod_rewrite. You need to specify the QSA flag to keep it.
httpd.apache.org/docs/2.4/rewrite/flags.html#flag_qsa
Thanks for fast responds without reading. Have a nice day!
Is it possible to change
host/index.php?variable=3
to
host/index.php/3
In my instance I'm using
host/bot?id=3
But I'd like it to be
host/bot/3 <-- This will be the only variable EVER used
How can I accomplish this, any links or code you can provide?
Thanks in advance!
GET /hotels/:id Hotels.Show
Segments of the path may be matched and extracted with a : prefix.
The :id variable above will match anything except a slash. For example, /hotels/123 and /hotels/abc would both be matched by the route above.
Extracted parameters are available in both the
Controller.Params map
and via Action method parameters.
https://revel.github.io/manual/routing.html
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.
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...
Im newbie here.I have a problem with codeigniter segment() method.I referred 6th segment of URL at href($this->url->segment(6)) but when i click the link it goes to full URl/6th segment.i.e
I want my link will be go here www.webcoachbd.com(this is 6th segment of my URL)
but it goes http://www.example.com/controller_name/method_name/segment1/segment2/segment3/www.webcoachbd.com
Are you doing this in your view?
I dont know if $this->uri->segment will work inside views, never needed it myself.
Instead grab the URI inside your controller and pass it back to the view.
$this->load->view('some view', array(
'link' => $this->uri->segment(6)
));
-
link
Although I dont really understand why you would want to do that.
Its not url but uri
$this->uri->segment(6);
and i think you are missing = operator in the anchor
MyLink
From the resulting URL that you posted, it looks like you might be missing a forward slash.
link text
This would force the URL to forward to the root of your site, rather than to that location inside the current folder that the browser thinks it is in.