Default controller (under modules) not loading under HMVC, CodeIgniter, throws 404 err - codeigniter

Just migrated my CI from localhost to live. Everything works fine on localhost with same settings.
Here're the folder/file structure and contents of routes.php
-application
--controllers
---Home.php
--modules
---specs
----controllers
-----Specs.php
----models
----views
$route['default_controller'] = 'Specs/index';
//$route['default_controller'] = 'Home/index';
$route['404_override'] = 'Errors/show_404';
$route['translate_uri_dashes'] = FALSE;
Both Specs and Home controllers have index method. When I load the home page url with Specs/index as default controller, I get 404 error. But if I change the default controller to Home/index, it loads just fine. Strange. Everything else works just fine on whole site. Can't figure out.
The website is live but I'm not sure if providing url is allowed, so I'm including spaces in it. It's unspecs dott comm. Admin/Mods may please remove if url isn't allowed.
Thanks for reading.

I think you are doing mistake in routing, for HMVC it should be like that -
$route['default_controller'] = '<folder name>/<controller name>/<function name>';
$route['default_controller'] = 'specs/Specs/index';
Please follow this, hope it will work fine.

Try this https://stackoverflow.com/questions/6529026/codeigniter... But better use standart folder for default controller /application/controllers

Related

Allow URLs with Dashes on azure websites

I am trying to make an SEO friendly link for a downloads page
using codeigniter hosted on Azure Websites, now this is working:
www.example.com/downloads/viewfile/34
now when i generated this link :
www.example.com/downloads/viewfile/my-nice-file-name-34
the Url rewrite works great locally on a WAMP server, but when deployed to the remote (Azure Webites IIS ?) it gives the error:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
I believe that the cause is: dash symbols are not allowed on IIS but is there a way arround ?
After all, i found out that its not the dash symbols that are causing the problem, but the words in the url itself
like yesterday i had www.example.com/downloads/viewfile/example-file-34
to some reason, having your domain-name in the url segments makes that error apear, so i simply replaced "mydomain" into nothing before generating the Url segment
$fileName = str_replace('mydomain','',$fileName);
return url_title($fileName.$fileId);
Now the same link above is www.example.com/downloads/viewfile/file-34 and its working fine.
i also noticed that same behavior is experienced when using some words like : ajax, json.
I hope this would be helful to somone.
In your routes.php file
Find
$route['translate_uri_dashes'] = FALSE;
Replace with
$route['translate_uri_dashes'] = TRUE;
You may need to look also into
URI Routing Codeigniter 3
http://www.codeigniter.com/user_guide/general/routing.html
Codeigniter 2 URI Routing
http://www.codeigniter.com/userguide2/general/routing.html

hmvc codeigniter uri routing

I have and CI hmvc structure as below:
application
config
config.php
routes.php
...
modules
login
personal
config
config.php
routes.php
controllers
libraries
models
views
HMVC works fine. So, here's my problem: Inside /modules/personal/config/routes.php i have this:
$route['personal/empleados/actualizar.legajo'] = 'personal/empleados/actualizar_legajo/';
$route['personal/empleados/nuevo-cargo'] = 'personal/empleados/nuevo_cargo/';
But it doen't work. The file is loaded but routing doesn't work.
If i cut and copy these two lines and paste them inside: /application/config/routes.php, works.
Can anybody tell me why ? Because i have several modules and i would like to do this inside each modules/module-name/config/config.php
Thanx, in advance.
Have you tried to set the default controller in each module ?
You may also need to add the folder path.
modules/personal/config/routes.php
$route['default_controller'] = 'personal';
// OR //
$route['default_controller'] = 'personal/personal';
Thanx for your answer.
I set my default controller as you tell but it fails anyway.
On the other hand i found a solution (?) as follow on modules/module-name/config/routes.php
$route['personal/empleados/nuevo.cargo'] = 'empleados/nuevo_cargo/';
and... IT WORKS. I don't know why. But it works.

Unable to run the app on hosted server

I have just installed Ci framework and tried on my local some basics according to the tutorial.
http://ellislab.com/codeigniter/user-guide/tutorial/static_pages.html
On local machine, everything was OK and page was displayed.
Than I upload project to the server (I am using wedos web hosting where I already have som web which is working correctly) but this is not working for the application which I copied it here. When I type the URL I got 404 error.
On my webhosting service I have www folder where i put my index.html file. Than when i type www.mydomain.eu I get this index.html file. Than I have subfolder www/folder/index.html Than when i type www.mydomain.eu/folder i get this page so it is ok.
Than i have www/folder2/here i unzip CodeIgniter framework and when i type www.mydomain.eu/folder2, 404 Page Not Found appears. The error is not general error from browser but generated from the CI framework.
I have created my own controler in application/controllers/mycontroller.php
<?php
class Mycontroller extends CI_Controller {
public function view($page = ‘enter_form’)
{
$data[‘title’] = ucfirst($page); // Capitalize the first letter
$this->load->view(‘templates/header’, $data);
$this->load->view(‘pages/’.$page, $data);
$this->load->view(‘templates/footer’, $data);
}
}
And I have following structure of views:
views/pages/enter_form.php
views/templates/header.php and footer.php
And the following settings:
1) $config[‘base_url’] = ‘’; but I have tried ‘http://mydomain.eu/’ and ‘http://mydomain.eu/www/’ or ‘http://mydomain.eu/www/folder2/’
2) $route[‘default_controller’] = ‘mycontroller/view’;
$route[’(:any)’] = ‘mycontroller/view/$1’;
Thank you for any help
Sounds to me like there is either a configuration issue or a rewrite issue going on. Do you have a .htaccess file in your CI root folder where your index.php file lives? Seeing that you are depending on the CI to pick up any uri and reroute it to a specific route, this might be the issue. I've ran into issues with this before on different hosts. Make sure mod rewrite is enabled and make sure your .htaccess is something similar to this:
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|assets|uploads)
RewriteRule ^(.*)$ /index.php/$1 [L]
Ok, so it seems like the typo somewhere, because when I used the default CI welcome pages, it works. So I will try to find the typo myself and i will see...

Routing issue with 404_override

I'm having an issue with 404_override in CI 2.02. Here is my default controller and override:
$route['default_controller'] = "home/index_controller";
$route['404_override'] = "misc/site_map";
This line uncommented gives me this error:
Unable to load your default controller. Please make sure the
controller specified in your Routes.php file is valid.
But commented, I get a 404 error. So something in the override is causing the problem. I just don't know what. I've tried various MY_Router files and they don't help. Anyone have any suggestions about how I can fix this?
I've eliminated my .htaccess file as the problem by deleting it from the server and then trying to access a controller that doesn't exist like this: http://domain.com/index.php/doesnotexist. I still get the error.
For anyone else coming here with this issue, this is/was a bug in CodeIgniter itself to do with 404 pages not being able to be included in subfolders.
Bug Discussion Including Fix on GitHub
You have forgotten to add the default controller that will be used when you first load your website, in your routes.php you need to add this, it is required which is why you're seeing the errors being thrown.
$route['default_controller'] = 'index'; // this will need to be changed to your default controller
$route['404_override'] = 'misc/site_map';
EDIT:
Okay, you must make sure you enter the correct controller name you wish to load as the default, for example you have home.php in your controllers folder, you must enter home as the default. Optionally, you can define segments that are functions in your home.php class file, e.g. home/function_name.

Request not routed on CodeIgniter

I've got a working CodeIgniter website on my machine. However, when I move it to the live server, it says that it is unable to determine what should be displayed. I checked the paths, base URL and .htaccess and everything seems to be correct. How can I find out what the problem is?
Edit: This is the content of routes.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$route['default_controller'] = "";
$route['404_override'] = '';
The error message does suggest that CI is attempting to fall back to the default controller which you have not specified. Assuming that the controller you are calling does exist this suggests that the problem might be to do with the server configuration and the way it is handling the URLs.
Try changing the URI Protocol in the config.php file (line 47). The default is 'AUTO' which works most of the time, but I have known servers that didn't like this. The comments in the file suggest various values you could try.
From the code supplied above, there is no default controller. CI requires a default controller is set, hence the error message.
If you have set one, then the problem isn't related to the above code.
You should setup your default controller in routes.php, for example
$route['default_controller'] = "home"; // home is the name of the controller

Resources