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
Related
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';
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
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';
Generally in CodeIgniter we get this structure of URL :
domain/controller/function
So suppose I went to some user's profile then URL would be :
domain/user/profile/username
How can I change that to
domain/username
OR even more better if
domain/u/username
where the middle part is what i decide.
Any Suggestions?
You can user routes.php for this purpose
Suppose you want a url like
domain/u/username
Then in routes.php you can specify the routing rule like below:
$route['u/(:any)'] = "user/profile/$1";
This specifies that if a url comes like '/u/anyvalue' then execute user/profile/$1
where $1 will be the anyvalue
As you might know, the URL for codeigniter is build like this. In my case, I have:
http://example.com/subfolder/class/function/ID
Is there a way with codeigniter (or htaccess) to create this url in a much shorter url like this:
http://example.com/ID
Kind regards, Senne
In the application/configs/routes.php file, you should be able to add something like this:
$routes['(:num)'] = 'your_controller/your_function/$1'
You can read more about custom routing here: http://codeigniter.com/user_guide/general/routing.html
You can do this by using Url Routing in CodeIgniter.
$route[':any'] = "subfolder/class/function/$1";