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
Related
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 created a login website, and my URL became like this
http://localhost/koperasi/index.php/cukl/index
how to make my url like...
http://localhost/koperasi/index.php/cukl
because I want to make a crud program but I think I have a problem in the url
**
my previous program using http://localhost/lee/index.php/buku so my page can entered CRUD on http://localhost/lee/index.php/buku/ubah
but now my newer program url is http://localhost/koperasi/index.php/cukl/index
how and where to change the url? is in the controller? model? or view?
I think, firstly you have to add an htaccess file which will remove index.php in your URL.
and inside the route.php file, you can define a new URL which you want.
Like this.
$route['cukl'] = 'cukl/index';
On my local server, I have setup a website using Codeigniter which opens up fine using below URL
I have a different kind of query regarding rewriting URL
http://localhost/mywebsite
Actually the real URL is below
http://localhost/mywebsite/page/
Which I want it to work as root url as
http://localhost/mywebsite
So I have done it by adding it as default controller in config.php
But now I have another URL as
http://localhost/mywebsite/page/mypagename
Which should open as
http://localhost/mywebsite/mypagename
How can I do it?
You can define a custom route in /system/application/config/routes.php - for example:
$route['abc'] = 'controller_name/abc';
Then, http://mydemosite.com/abc
goes to http://mydemosite.com/controller_name/abc
see https://ellislab.com/codeigniter/user-guide/general/routing.html for more information of URI Routing.
I hope this can be helping you.
I got it solved using routing method as below under config/routes.php
$route['([^/]+)/?'] = 'page/$1';
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";
Hello I want to change the URL of a page
at the moment it looks like
www.domain.com/privacy
and I want it to look like
www.domain.com/privacy-policy
since it looks much better. Is there a way to achieve this in codeigniter?
CodeIgniter uses the routes defined in config/routes.php to rewrite URLs.
Add a line like this: $routes['privacy-policy'] = 'controller/action';
For full documentation, read the user guide:
http://ellislab.com/codeigniter/user-guide/general/routing.html