I am getting problem on codeigniter routing when routing url starts with variable like following -
$route['(:any)/(:any)'] = "home/index/0/N/DealsAmount/ASC/$1/$2";
i can to able to configure other routing url when i am passing values through url.
Example:
Following things work perfectly
$route['About-Us/Team'] = "aboutus/team";
$route['About-us/Jobs'] = "aboutus/jobs";
$route['About-Us/FAQ'] = "aboutus/faq";
But i use this url using varible like following --
$route['About-Us/Team/(:any)'] = "aboutus/team/$1";
$route['About-Us/Team/(:any)/(:any)'] = "aboutus/team/$1/$2";
$route['About-us/Jobs/(:any)'] = "aboutus/jobs/$1";
$route['About-Us/FAQ/(:num)'] = "aboutus/faq/$1";
then it redirects to the home page that means this routing is not working here $route['(:any)/(:any)'] is working how can i able to rout these types of url can you please advise me.
You have to put the routes with :any at the bottom. If you put it at the top other routes never get caught. This should be OK:
$route['About-Us/Team/(:any)/(:any)'] = "aboutus/team/$1/$2";
$route['About-Us/Team/(:any)'] = "aboutus/team/$1";
$route['About-us/Jobs/(:any)'] = "aboutus/jobs/$1";
$route['About-Us/FAQ/(:num)'] = "aboutus/faq/$1";
$route['(:any)/(:any)'] = "home/index/0/N/DealsAmount/ASC/$1/$2";
Related
I'm unable to make SEO friendly category based URLs in CodeIgniter :
Current url:
http://www.website.com/view/T-Shirt/round-neck
My route code:
$route['view/(:any)'] = 'Frontend/sub_sub_category/$1';
But i want to show like this:
http://www.website.com/T-Shirt/round-neck.
try this:
your route should:
$route['default_controller'] = 'product';
$route['(:any)/(:any)'] = 'product/product_category/product_sub_category';
You Will get:
http://www.website.com/T-Shirt/round-neck
get more help with refer link: codeigniter URI Routing
also go with stack overflow link
I have writing codeigniter URL routes for my site, the route is
$route['index.php/([a-zA-Z0-9---_%])+'] = 'site/index/$1';
when i try to access the link like as below
http://localhost/site/index.php/india
is not working, it redirects to 404 page.
If you have a link
http://localhost/site/index.php/india
You need write this route:
$route['site/index.php/(:any)'] = 'site/index/$1';
I am making an API in PHP.
I want to add .json to the URL like this:
www.example.com/data.json
I am using CodeIgniter.
I have tried solving this in routes config file like this
$route['default_controller'] = 'data';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['/data.json'] = "/data/index";
You can add a url suffix in CodeIgniter by going to the config.php file and changing url_suffix:
$config['url_suffix'] = '.json';
This will make your website accesible via www.example.com/data and www.example.com/data.json
Check the documentation
If you want to enable it in some pages only you can use the routes like this:
$route['data.json'] = 'data/index';
If it's a page with dynamic path for example data/some-id.json use this:
$route['data/(:any).json'] = 'data/index/$1';
I am working a codeigniter project. for example I have a controller Blog and a method category with param.
When i go to a link
Developer Blog
it works fine. which redirect to a page developer blog.
Is it possible to rewrite the url as domain.com/blog/developer-blog dynamically ? Thank you.
Open your application/config/routes.php and try following (if you want exact as mentioned in question)
$route['blog/developer-blog'] = 'blog/category/2';
$route['blog/user-blog'] = 'blog/category/3';
for dynamic routing you may use this
$route['blog/developer-blog/(:num)'] = 'blog/category/$1';
$route['blog/user-blog/(:num)'] = 'blog/category/$1';
so your URL now should be looks like https://domain.com/blog/developer-blog/1, https://domain.com/blog/developer-blog/2
or https://domain.com/blog/user-blog/1, https://domain.com/blog/user-blog/2 etc
for more see http://www.codeigniter.com/user_guide/general/routing.html
i tried to find solution, but i think i am quite doing something wrong here,
i hope any one with good knowledge of codeigniter routing can help me in this regard.
what i want is that,
i have default controller named main
$route['default_controller'] = "main";
$route['404_override'] = '';
my site urls are like
mydomain.com/main/#home
mydomain.com/main/#search
mydomain.com/main/#login
what i want is to remove/hide the main from center and links can directly work.
like this
mydomain.com/#home
however i did succeeded a little using codeigniter documentation.
This is what i did to achieve it.
in route file i added this
$route['(:any)'] = "main/$1";
it worked but it messed up with other links.
First now domain.com/main/#home stopped working.
second, now i cant have other controller name here??
i mean if i try this domain.com/virtualvault/#search, it wont work..
What i am trying to have that,
When i go to domain.com/main/#home it should go to home page
and also when i try domain.com/#home it should also go to same home page
not to forget that i want other controllers to be working fully.
i mean, domain.com/othercontrollername/#function should work.
what and how to achieve it, .htaccess or route php file..
i even tried this below route code.
$route['#+(:any)'] = "main/#+$1";
but i am no good in this routing or .htaccess files.
any ideas how to achieve it??
// The below line is for the old controller to work as before
$route['main/(:any)'] = "main/$1";
//This line is for making other controllers work as before, you have to put them all
$route['virtualvault/(:any)'] = "virtualvault/$1";
//This is the last line; the order is important
$route['(:any)'] = "main/$1";
If you need only those three URLs (home, search and login) to work without the controller name, just put the three of them in routes.php ($route['login'] = "main/login";, etc.) and use no wildcards in order to prevent other URLs from getting rerouted.
So, all of them should be:
$route['home'] = "main/home";
$route['search'] = "main/search";
$route['login'] = "main/login";