Welcome Guest, Not a member yet? Register   Sign In
Home page routing with $route['(:any)']
#1

[eluser]chavansoft[/eluser]
Hello,

Any one please help me figure out what should i do for the following

I have a Website in localhost

i have lots of pages like

http://localhost/current/b/index.php/Category

http://localhost/current/b/index.php/news

http://localhost/current/b/index.php/page/About-Us

http://localhost/current/b/index.php/contactus

Home is my Default controller

Now i have certain products say saloon, carstation, toothbrush and so on...

i need this to be like the following url


http://localhost/current/b/index.php/saloon
http://localhost/current/b/index.php/toothbrush
http://localhost/current/b/index.php/

I have tried using this $route['(:any)'] = "home";

in the below one

$route['default_controller'] = "home";
$route['scaffolding_trigger'] = "";
$route['news/:any'] = "news/index";
$route['Categories/:any'] = "Categories/index";
$route['product/:any'] = "product/index";
$route['page/:any'] = "page/index";
$route['search/:any'] = "search/index";
$route['(:any)'] = "home";


this does not allow the other pages work. Whatever url i click it goes to home page.

Please help me to fix this error

Thanks

Regards

Chavan
#2

[eluser]AoiKage[/eluser]
That's because "$route['(:any)'] = 'home';" will ALWAYS redirect every url to the home controller.

And the other ones are wrong, btw.

Try with something like this:
Code:
$route['default_controller'] = "home";
$route['news/(:any)'] = "news/index";
$route['Categories/(:any)'] = "Categories/index";
$route['product/(:any)'] = "product/index";
$route['page/(:any)'] = "page/index";
$route['search/(:any)'] = "search/index";

Although that wouldn't make any sense if you don't pass the parameter you insert as a variable...

Maybe something like this would make more sense:
Code:
$route['default_controller'] = "home";
$route['news/(:any)'] = "news/index/$1";
$route['Categories/(:any)'] = "Categories/index/$1";
$route['product/(:any)'] = "product/index/$1";
$route['page/(:any)'] = "page/index/$1";
$route['search/(:any)'] = "search/index/$1";

I don't know of a way to strip the various 'product', 'page' etc from the actual URL... if that's what you were trying to do.
#3

[eluser]chavansoft[/eluser]
Thanks for the reply AoiKage

But this not the one i asked for.

The below works for me

http://localhost/current/b/index.php/saloon
http://localhost/current/b/index.php/toothbrush

the saloon is the query string i pass and its not a controller.

Please help me on this
#4

[eluser]AoiKage[/eluser]
Hmmm, okay, now I got it. The problem is I don't even know if it's possibile, and if it is I don't know how to do it. Sorry Sad
#5

[eluser]Phil Sturgeon[/eluser]
There is not much point listing all the controllers that should work normally, just list the special one.

Use $route['404_override'] = 'pages'; so all 404 calls go to the pages controller, then use _remap() to show the specific page.

AoiKage: Those routes were not wrong. You only need to wrap :any with () if you want to return the segment and use it in the value. ie: $1. If you are just comparing the pattern of the URL and not re-using sements then there is no need to wrap the :any.
#6

[eluser]chavansoft[/eluser]
how to use use_remap() and why it is so used
#7

[eluser]Phil Sturgeon[/eluser]
http://ellislab.com/codeigniter/user-gui...llers.html
#8

[eluser]chavansoft[/eluser]
Thanks




Theme © iAndrew 2016 - Forum software by © MyBB