Route to a specific controller in codeigniter - codeigniter

I am using codeigniter for the back end of my website.
For that I have created admin folder inside my controller.
My issue is that when i type the url
http://localhost/varma/admin
It should redirect to the file login.php which is inside the contollers/admin

Inside the routes.php write this code:
$route['admin'] = 'admin/controller/function';

Try this code in your routes.php file ,
$route['admin'] = 'admin/login/your_login_function_name';

$route['admin']='admin/login';
where login the is login function name

Related

URL redirection in codeigniter

I need help in url redirection in codeigniter,
I have following url
http://test.com/MyProject/My13d2lnbGlsZGNtcWt0Z2w=
When I click above url, then it should redirect to my function like,
http://test.com/MyProject/api/TestingManagement/getMyUrl/My13d2lnbGlsZGNtcWt0Z2w=
We can do it with CI routes or .htaccess, but how?
Thanks in advance
For Routes you can write following as last rule:
$route['(:any)'] = 'api/TestingManagement/getMyUrl/$1';

Redirect non-existent url to home in Codeigniter

A client has seen a non-existent page show up in Google Analytics and would like it redirected to the home page. I am new to CodeIgniter.
I don't see an .htaccess file in this project in the root directory, and tried the following in the routes.ph but it did not work. Do I need to add something in routes.php?
$route['strangepage'] = 'Home';
Try This--
Please put in application->config->routes.php
$route['default_controller'] = 'home';

Need to change hmvc routes in CodeIgniter

I have CodeIgniter HMVC application and I want to change route as per requirement.
Now I have website/product/detail/url, and I want to change it with website/url.
Once I set URL from admin side it will redirect to my route.
This is what I have now:
$route['Products'] = "Products/detail/d101productdatatest(this is url)";
And I want in my url like website/url and it will open same page what I have with website/product/detail/url
From the given library:
https://www.codeigniter.com/userguide3/general/routing.html
routes as above:
$route['controller/function'] ='website/Products/detail/d101productdatatest';
But as per your given question:
you cannot manipulate url using routes
you can map same function with different url using routes
you have to use .htaccess to redirect to specific url after hitting the previous given url.
htaccess example:
Redirect /index.html /new/
Redirect /index.html /default.html
Redirect /private/ http://www.example.com/private/
Redirect /img/logo.gif http://www.example.com/images/logo.gif
Hope this answer helps you out !!
cheers

Route to admin page in codeigniter

I'm working with Codeigniter and i want to have a URL like this:
admin.domain.com
And then route it to the real controller and function.
It means I don't want to have a URL like this : www.domain.com/admin.
I have one controller for back-end and another for front.
This is my default controller in route file:
$route['default_controller'] = "home";
so how should i do it? with route file or htaccess file or some another way?!

CodeIgniter URL routing - SEO friendly URL

I've created a new route for my site:
$route['default_controller'] = "welcome";
$route['(:any)'] = "welcome/index/$1";
$route['404_override'] = '';
And this works fine in my site when URL is like this:
http://mydomain.com/first-article
http://mydomain.com/second-article
*my controller is just welcome.php
but
i also have a controller for the admin and the URL for the admin is:
http://mydomain.com/admin
What will I add to the routes file to ignore the /admin and other controllers inside the admin?
You can replace the welcome/index/$1 route with:
$route['^(?!admin).*'] = "welcome/index/$1";
This basically says, that if a URI that does not start with "admin" should route to the welcome/index method and pass the contents to the index method. Otherwise, handle normal routing with admin being the controller.
Open application/config/router.php and change the
$route['404_override'] = '';
to
$route['404_override'] = 'router/index';
You can use all controllers as the normal way.
When you try to use a controller that is not exists, you should route it to a 404 controller.
Create a controller named Router.php as a controller structured for CodeIgniter.
In the index method inside Router.php, query for related sef url and do required operations. All requests that routes to an undefined controller will be handled by router/index method. Others will be redirected to related controller as usual.
You might want to use header codes to point that related page is not 404.

Resources