codeigniter 3 URL Remap - codeigniter-routing

I am trying to remap all old URLs http://www.example.com/ipranges.php?reqinfo=180.94.79.0-180.94.79.255 in my codeigniter 3 but its not working. here is my route for this. Can someone help? Thanks
$route['ipranges.php?reqinfo=/(:any)'] = "ipinfo/ipranges/$1";

-codeigniter is using uri segments , and there is "ipranges.php..."
in your routes which is not allowed and can't be used in codeigniter.
-In codeigniter url->
there is 1st segment which indicates controller ,
second segment point to method and
third and so on, are the parameters to method.
-so here is url=> www.example.com/controller/method/parameter......
-if you are using routing,than you can remap them as
-----www.example.com/slug
--Here in routes.php
$route['slug'] = "controller/method/$1";

Related

set a parameter with default value to route url in django

Hy all!
I'm new to python / django and I came across a problem that I can not solve. I have a route configured for the site's home (1) and a route configured for categories (2):
1) url(r'^$', IndexView().home, name='home')
2) url(r'^categoria/(?P<path>.*)/$', IndexView().by_category, name='by_category')
I need to set my home url to open a category by default, something like www.mysite.com/c=defaul_category
I tried in some ways, including: url (r '^ / (? P \ w +) / $', IndexView (). Home, name = 'home'). But I know it's incorrect.
So... I have no idea how to do this. Could someone help me?
Thank you
You should tell django that path in by_category url may be omitted. You have at least two options here:
1 - create one more url without path but with passed path variable as 3-rd argument in url:
url(r'^/(?P<c=vinhos>\w+)/$', IndexView().home, name='home')
url(r'^categoria/(?P<path>.*)/$', IndexView().by_category, name='by_category')
url(r'^categoria/$', IndexView().by_category,
{'path': 'default_path'}, name='default_category')
2 - change regex pattern to make it possible to omit path parameter. Here | (or sign) added in the end of path group:
url(r'^categoria/(?P<path>.*|)/$', IndexView().by_category, name='by_category')
More about omitting url parameters Django optional url parameters

express router not working with routes that include regex

I'm new to node and unable to create a simple route which will include regex as on of the parameter
// student.js - route file for route /student
app.get('/student/:/^[a-z0-9-]+$/', function(req,res){
res.send('student found');
});
when i hit localhost:3000/student/student-slug it says Cannot GET /student/student-slug
two more question
1) how to get param which is of regex, usually we can do this var _student = res.param.student_name but i'm unable to think for the regex
2) how to set optional param, let's say for pagination, route is like
/list/students/ will show list of last x student but /list/students/48 will offset that value to 48th row
this question may be duplicate but i'm unable to find answer
You need to encode the uri string before pass to request and decode it in your route handler.
Usage is very clear:
encodeURIComponent(str);
And for decoding use:
decodeURIComponent(str);
check the official documentation here
also do checkout this blog post on escape vs encode vs encodeURIComponent

Routing issue in codeigniter regex

Route are defined as
$route['hotels/([a-z]+)/(:any)'] = "hotels/city/$1/$2";
$route['hotels/placename/fivestar'] = "hotels/placename/star/fivestar";
I want to execute the city action in hotels controller when some one type url like
http://website.com/hotels/myspecificcity/fivestar
the above first route is not working. it always load 2nd route . can some one please guide me
i don't want to remove 2nd route though as i will using for other purposes
Thanks

Mapping urls in routes.py

I am using web2py and builing a REST api and have one of my URLs set up like this:
routes_in (
('/myapp/something/{?P<id>.*)/myfunction', /myapp/default/myfunction/\g<id>')
)
routes_out = (
('/myapp/default/myfunction/\g<id>', '/myapp/something/{?P<id>.*)/myfunction')
)
If my app is setup this way my function is not even entered into and I get an invalid request if I remove the id argument from the url that my url is being mapped to i.e. remove g<id> from above, I enter my function but the argument is not being captured.
I cannot change the structure of the URL as per my requirements and I am not sure how to go about this.
I would appreciate any pointers.
Thanks,
nav
The above does work in web2py I found that some other area of my code was breaking.

Zend Framework how to configure a router GET parameters

URL
somedomain.com/?_escaped_fragment_
try it:
routes.escaped-fragment.type = "Zend_Controller_Router_Route_Regex"
routes.escaped-fragment.route = "\?_escaped_fragment_"
routes.escaped-fragment.defaults.controller = "index"
routes.escaped-fragment.defaults.action = "someaction"
but he does not see the GET parameter ?_escaped_fragment_
and run
IndexController::indexAction
The ZF router operates on the path only, query string params are stripped off before the route matching occurs, so you're not going to be able to get this working easily. Your options are:
Change your URL structure
Rewrite this URL in .htaccess
Extend/replace the default router to check the query string before doing the standard routing