Route to admin page in codeigniter - 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?!

Related

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 a specific controller in 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

How to hide controller and action from URL in DEFAULT route

I'm using MVC and having trouble figuring out how to hide the controller and action in the URL.
I have seen many things on how to hide the controller or the action but most are not for the default controller.
My controller looks like this:
routes.MapRoute("Default",
"{controller}/{action}/{id}",
new{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
});
When you navigate to my site the URL looks like this:
www.mysite.com/Home/Index
I need it to hide the "Home" and "Index" so it looks like this:
www.mysite.com
I have the default route as the last route in the routeConfig file. Any help would be appreciated.
Is this your root URL. If so than use the following code in your routes.rb file.
root "home#index"
then you will get the www.mysite.com
However, there are many techniques to hide the controller and action from the url. Please have a look on this post rails remove controller path from the url

how can url masking in codeigniter?

my url www.xyz.com/as/as/as/as but .com after all controllers and method hide or minimize to how and use in codeigniter.
how can url masking my url www.abc.com/as/a/s but show only www.abc.com only. how can solve this error in codeigniter
You could just set the default_controller in routes.php to;
$route['default_controller'] = 'as/a/s';
https://ellislab.com/codeigniter/user-guide/general/controllers.html#default

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