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]
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
Here I am with a question that might have been heard many times but still I could not find a perfect solution for that.
My question is that : How to hide the module name , controller name and method name from URL in php codeigniter.
Yes I have googled a lot and have seen many of the videos but did not reach to a success.
Below are the lines of code of different files:
<li>Home</li>
In above code there is a ul li menu bar in which when I click on Home it should redirect to the homeIndex method of UserController and user module.
UserController is the Controller name
homeIndex is the mentho in UserController
and user is the module. I am following HMVC structure here.
Currently when I click on home it creates below url
http://localhost/KWeds_svn/kweds_hmvc/index.php/user/UserController/homeIndex
Below is my .htacces file code that I am currently using
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
Below is the base_url defined in config.php
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = "$root";
$config['index_page'] = 'index.php';
My expected output for the url is only
http://localhost/KWeds_svn/kweds_hmvc/
Please let me know how can I hide module name ,controller name and method name.
There is a simple solution to using URI routing in CodeIgniter.
If you open the routes.php file in the config folder you can map URI's to controllers and methods.
In your case, it would work something like this:
$route['KWeds_svn/kweds_hmvc'] = 'UserController/homeIndex';
Also you need to figure out how to remove the index.php from the URI, to do this, use the following steps:
Go to config.php and change
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
Then go into the document root folder (where the config, application folders are held) and create a new file called .htaccess, in this file write the following code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
If you are hosting your own server, you may need to enable the rewrite module in apache. To do this, go to the command line for your server and type the following:
sudo a2enmod rewrite
Hope this helps!
I am trying to move my codeigniter application from my WAMP installation to a shared host (justhost) for the first time.
In my public_html folder I have included all of the folders and files for my application. So for example I see my "application" folder when I open public_html in my file manager.
I have a controller "Lander" which I have set to be the default via $route['default_controller'] = 'Lander'
When I go to www.mywebsite.com I do see the view that gets loaded from the Lander controller. The problem is that within that view I have a link Log in that, when I'm running on WAMP, opens the login controller, which is in the same folder as the Lander controller. When I click this link from the hosted site the URL goes to www.mywebsite.com/Login, but I get 404 not found.
In Config.php
$config['base_url'] = 'http://stackoverflow.com/';
$config['index_page'] = ''; # remove index.php
.htaccess should be
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
and Links should be
Log in
There should be a controller call login or in routes you should define
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.
I don't usually post messages on the web to get help but I feel that I have tried everything and I am stuck.
I wanted to upgrade CodeIgniter from version 2.2 to version 3.0.3 (I tried v3.0.2 too) and I followed the corresponding guide on codeigniter.com. But now, only the default controller is loaded, no matter the url.
I have searched on the web and I have found out that it could come from:
the htaccess
the application/config/config file
the application/config/routes file
the new Ucfirst rule for the filenames (controllers, models...)
But I still don't have the solution...
The files in "applications/controllers" are all Ucfirst.
Everything was working fine before (with version 2.2), so WAMP should be correctly configured (mod_rewrite enabled etc...). Moreover, I have tried and succesfully loaded a clean instance of CodeIgniter 3.
Models, Controllers and Views are loaded correctly, I can change my default controller and it will load the correct view (with requests done by controllers and models). But it only loads the default controller, no matter what the url is (in the browser). Even if it does not exist, I never have the 404 page. Except if I specify an incorrect "default_controller" (in the file "routes.php").
It has to be a routing issue...
Here is some of the tests I have done:
Table of tests
Here is my htaccess file (I have tried other ones on the web too, the result is the same):
RewriteEngine On
#Checks to see if the user is attempting to access a valid file,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Enable access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
Here is my "application/config/routes" file:
$route['default_controller'] = 'dashboard';
$route['404_override'] = 'auth/e404';
$route['translate_uri_dashes'] = FALSE;
Any help would be appreciated :-)
Thank you !
SOLUTION
$config['enable_query_strings'] was set to "TRUE" in the file "application/config/config.php". Setting it to "FALSE" solved the issue. So simple...
try putting the index method in the routes, for example instead of this
$route['blog'] = 'blog';
try this
$route['blog'] = 'blog/index';
and if that doesn't work, can you confirm you have set the correct base url in application/config/config.php ?
In codeigniter 3 wamp
I use this htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
With your error 404 over ride can not be in sub folder.
Change
$route['404_override'] = 'auth/e404';
To
$route['404_override'] = 'e404';
And on config.php
$config['base_url'] = 'http://localhost/your_project/';
// You can leave base url blank but not recommended because when you try to submit forms make cause issue.
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';