I use codeigniter for my project and custom route 404 page.
My route file :
$route['404'] = 'frontend/maintain/page404';
$route['404_override'] = '';
On localhost, website route right to my custom 404 page, but on live server it does not, it route to the default 404 page of codeigniter ?
i do not understand why it like that. Please tell me why ? Many thanks all!
On Codeigniter 3 versions the 404 override route only works on one level does not work in sub folders
$route['404_override'] = 'page404';
Controllers > Page404.php
Related
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';
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
codeigniter working on my local machine but not on server.
administrator/application
administrator/system
administrator/assest
I tried some .htaccess files but codeigniter not working.
On codeigniter 3 Check all your controller and model make sure the filename and class name have there first letter as uppercase example Welcome.php and class Welcome
Also if you have not configured your index.php to be removed on either codeigniter 2 or 3 versions then you will need to add in url each time you use a link.
Live Server URL Example
http://www.example.com/index.php/site
Localhost URL Example
http://localhost/project-name/index.php/site
Some Htaccess Example Link
How to remove index.php codeigniter 2 & 3
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
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.