CodeIgniter routes are not working - codeigniter

I've defined following route in config file as follows.
$route['apartments/(:any)'] = 'apartments/view/$1';
If I give http://localhost/apartment_advertisement/apartments/shobha_complex like this in url it works perfectly fine.
If I give http://localhost/apartment_advertisement/apartments/shobha_complex/abcd/abcd like this in url it goes to the same page as above. So I needed error page for this url. Please help me how to control these urls?. The work would be more appreciated.

Do you mean display an 404-not-found error when request URL has an unwanted "tail"? You can modify (:any) to restrict accepted string. It's simple:
$route['apartments/(\w+)'] = 'apartments/view/$1';

Related

How to hide function and parameter from url in codeigniter?

this is my URL.
http://localhost/savyy/home/home_page/Islamabad
i want to show it like
http://localhost/savyy/home
i m using uri routing code
$route['home/(:any)'] = 'home/home_page/$1;
but nothings happen...it shows same URL. can anyone please help me ? please tell me how to hide function name and parameter.
I dont think it will work that way, the request is the route to controller. the request uri will be the same. you will still have the "home/home_page/islamabad" in your url. unless you redirect with the home_page() to home() and save the islamabad in a session.

Codeigniter URL routing solution for my website

I have a website that is developed with CodeIgniter. I have added the route for my url as follows:
$route['about_us'] = 'about-us';
Now I have a problem with that. I.e. when I am looking for the url www.mysite.com/about_us it works and at same time www.mysite.com/about-us is also working. I want only one url to work: the one with the underscore.
I have removed this to:
$route['about_us'] = 'about-us';
But the url www.mysite.com/about-us still works. It may cause duplicate content for my website in Google and so more page links also showing. Even I don't have that functions too. Like www.mysite.com/about_us/design. Likewise in about_us controller file index function only there, but design method calling in Google.
How do I resolve this problem?
You actually don't need a route here. The normal purpose of request routing the way you are using it is so that you can use hyphenated URLs when hyphens are not permitted in class and function names. I.E. you want the url to by www.example.com/test-controller, but you can't actually name a controller test-controller because the hyphen is illegal.
If you only want to have the underscored URL such as www.mysite.com/about_us then just remove the route completely and name the controller about_us. With no routing rules the hyphenated url should 404.

Laravel 4 - Duplicate Url

I am having a problem with the confide package for user authentification.
My problem is that when I login, I am redirected to the login page which throws an notFoundHttpException because the url I am redirected to is duplicated... looks like this:
http://www.mypage.dev/http://www.mypage.dev
My virtual host is set up like this here
https://github.com/daylerees/laravel-website-configs/blob/master/apache.conf
What is making this happen?
---EDIT---
Gathering more experience...
It seems that this occurs when the following redirect is used:
return Redirect::action('Controller#action')
If I use:
return Redirect::to('/action')
everything is just fine.
My route look like this:
Route::get('/action', 'Controller#action');
Change your Route to
Route::get('action', 'Controller#action');
Your current route's definition appends /action to the end of the current URL.
Because of the underscore, the url http://newsletters_app.dev is invalid according to filter_var($url, FILTER_VALIDATE_URL). Because of this, HTML::link() is generating a duplicate base. Solution is to simply remove the underscore from the URL.

Remove controller name from codeigniter 2 url path

I am having trouble removing the controller name from my url path on my localhost.
i have this url - localhost:8888/localhost/site_name/
i have been able to remove index.php from the url using my htaccess similar to http://codeigniter.com/wiki/mod_rewrite so that:
localhost:8888/localhost/site_name/index.php/controller_name
is now:
localhost:8888/localhost/site_name/controller_name/
but i can't remove the controller name from the path so that:
localhost:8888/localhost/site_name/controller_name/function_name/
becomes:
localhost:8888/localhost/site_name/function_name/
I am using only one controller, and i have added:
$route['^(function_name1|function_name2|function_name3)(/:any)?$'] = 'controller_name/$0';
$route['^(?!ezstore|ezsell|login).*'] = "home/$0"; /*similar variation i tried*/
and other variations to my routes file but it does not have any effect. i also tried using the _remap function but that does not help in this case.
Any help will be appreciated! Thanks
You can use a wildcard route,
$route['(:any)'] = "controller_name/$1";
Then when if you go to http://localhost/function_one/param1
it will call the controller controller_name the function function_once and pass param1 as the first parameter.
nb: I must point out, using only one controller for an entire site does raise warning bells for me, you may want to get your code design checked out, but that's just me.

Codeigniter URI Routing Issue

I have the following URL
domain.com/name/details/12345
I want it so if someone types in
domain.com/name/12345 it goes to the above
I am using $route[‘name/details/(:num)’] = ‘name/’;
But I get a 404 error when I try it.
From looking at the documentation:
http://ellislab.com/codeigniter/user_guide/general/routing.html
It looks like what you want is:
$route['name/(:num)'] = 'name/details/$1';
The route name/12345 is matched and routed to name/details/12345

Resources