here is my url structure-
http://example.com/demo
demo directory contain my all codeigniter application files. I set my base path like this
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = "$root";
and also set $config['index_page'] = ''; is blank. My .htaccess file contain-
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?$1 [QSA,L]
Suppose i have a controller called Home and contain one method called index. I have set it as my default controller like this on my routes.php
$route['default_controller'] ='home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
// Catch all route
$route['home'] = 'home/index';
Now the problem is when i am using in my localhost(wamp) it works well. But when I uploaded it to my server and go to this url http://example.com/demo it shows blank page. It should show home controller. I have checked it that if problem present in Home controller. Thats why I go to this url http://example.com/demo/home now its working fine but problem occurred when using the base url.
It's not needed to enter the route for your default controller.
Just remove the line with $route['home'] = 'home/index';; I think it's overriding your default configuration.
Related
I've been trying to find some other solutions online but none yet has worked as I need it to.
I'm working on a CodeIgniter project but, at some point I suppose I have edited something I should not. Now, when I try to call localhost/projectname/controller/function it does ALWAYS (no matter which controller, even if the welcome controller) it will load my index.php file, which is on the root folder of codeigniter (not Views), without any images or css whatsoever, just plain text.
My config.php:
$config['base_url'] = http://localhost:8080/projectname';
$config['index_page'] = '';
My routes:
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route[LOGIN_PAGE] = 'examples/login';
My .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
I've trying to install community-auth and now have been caught with the error, as previously I was just working on the index page design and only now have been trying to access other functions.
I'm using NetBeans 8.2 and XAMPP v3.2.4
This is the index page:
This is what I get while trying the access controllers/function this is the page loaded:
Any help? Any other information I should provide?
Remove the $route[LOGIN_PAGE] = 'examples/login'; from routes
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Once load the page and share the browser inpect console error
I have setup a CodeIgniter site but only the default routing seems to be working.
I have had to set it up as a sub dir of an overall site - so http://localhost/subdir is the default url - this seems to work with the basic out of the box routing.
I have added a Users controller with the following methods - login, logout, register so I was expecting http://localhost/subdir/users/login would work but I get :
The requested URL /subdir/users/login was not found on this server.
Apache/2.4.25 (Win32) OpenSSL/1.0.2k PHP/5.4.44 Server at apps.mediaforce.co.uk Port 80
My routes file is very basic so I tried adding a new route to it for the users controller but it made no difference.
$route['users/login'] = 'subdir/users/login';
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Where am I going wrong?
You don't need to include subdir in your route.
Hence update your $route['users/login'] to route to following:
$route['users/login'] = 'users/login';
Edit 1:
in your root create a .htaccess file if it doesnot exist and save the following content in it to remove index.php from your URL:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]
The app which i'm creating using codeigniter is loading on my localhost. But when i uploaded the same into cpanel its showing "404 Page Not Found".
I'm able to access default welcome controller other than this it shows 404 page not found.
Below are my configuration in application/config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
.htaccess configurations are as follows
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
configuration in application/config/routes.php are as below
$route['default_controller'] = 'login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
If I change the default_controller to welcome then welcome is loading fine.
--Thanks in advance
As said in the comments : Your controller's file name must start with an uppercase.
See http://codeigniter.com/userguide3/changelog.html
Changed filenaming convention (class file names now must be Ucfirst
and everything else in lowercase).
:-)
Divided controllers into folders, site in site folder, admin in admin folder (inside controllers).
But I can not access the controllers without putting the base of the same folder url, example:
I want to access like this: http://localhost/gabriel/projeto/about
But just so I can: http://localhost/gabriel/projeto/site/about
File 'htaccess' this so:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
'base_url' this so:
$config['base_url'] = 'http://localhost/gabriel/projeto/';
File 'routes' this so:
$route['default_controller'] = "site/index/";
$route['404_override'] = '';
$route['admin'] = "admin/login";
Already tried modifying the .htaccess but no result.
Inserting another line in the file 'routes':
$route['(:any)'] = "site/$1";
But putting that line it conflicts with the route ends and the Admin can receive only one parameter in Url.
How can I solve this problem? make dynamic route...
I'm not 100% sure this is what you're asking, but try setting the base_url in the config/config.php file
$config['base_url'] = 'http://localhost/gabriel/projeto/';
or set to whatever you want your site root to be
add this in your routes.php.. place it above all other $route variable...
$route['projeto/about'] = 'projeto/site/about';
Solved my problem as well:
$route['admin/(.*)'] = "admin/$1";
$route['(.*)'] = "site/$1";
Now this dynamic route
I have a default controller set:
$route['default_controller'] = "Home";
However, when I go to http://mydomain.com/, it says 404 Page Not Found, but when going to http://mydomain.com/Home, the controller loads fine. What could be the problem? I've been wracking my head for hours. My htaccess is posted here if needed. Thanks!
Turns out my problem was somewhat unrelated. I had to rename my default controller php file to lowercase and the controller class name to lowercase and everything started to work. When CI looks for the default controller file, it searches in lowercase for the file; if I name my controller file "Home.php" instead of "home.php," CI misses it on Linux (since Linux file systems are case sensitive).
There is nothing wrong with your routing, the problem is with your htaccess file. Try removing
ErrorDocument 404 /index.php
You have probably some .htaccess problem.
Tray this way:
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
config.php
$config['base_url'] = 'www.homepage.com';
$config['index_page'] = '';
routes.php
$route['default_controller'] = "yourcontrollername";
$route['404_override'] = '';
Without any additional information & code from your configs/controllers, I'd suggest checking config/config.php for these (both should be empty in normal cases):
$config['base_url'] = '';
$config['index_page'] = '';
IIRC, I have seen similar issue and it was related to these config variables. Hopefully this helps you a bit.
I sure this .htaccess solved all ubuntu users...
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
I have a default controller set:
$route['default_controller'] = "home";
it's working for me.