I have already tried all the possible solutions that I've find in SO, but I still unable to load my controllers without adding the index.php/ before (CodeIgniter), I'm not even able to load my default controller as CI throws a 404 error.
I am using CI 2.1.3
My config is as follows:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; //tested all the options
My .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Thanks for you time.
Kind regards.
Solution for :
" but I still unable to load my controllers without adding the
index.php/ before (CodeIgniter), I'm not even able to load my default
controller as CI throws a 404 error."
Use this .htaccess in your main folder i.e where the application is in.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If you are running on Linux Server add this code in your .htacess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
application/config/config.php
$config['index_page'] = 'index.php';
To
$config['index_page'] = '';
Related
I'm trying to build a shopping cart locally using PHP & MySQL. My main directory for my site is /Library/WebServer/Documents. I tried to set it up so that I can access localhost/project without the index.php.
Here's my htaccess:
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
My config code (extracted, not the whole thing):
$config['base_url'] = 'http://localhost/project/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Apparently there's an error with this. Even though I managed to access localhost/project without index.php, I can't view pages generated by my controller code (ex. if I try to go to localhost/project/welcome I get this error message: 'The requested URL /project/welcome was not found on this server.' localhost/project/welcome should take me to the Welcome.php page under my controllers folder.
Here's a snapshot of the file structure
Can someone explain to me what's wrong with my code?
Do you mean without .php?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
OR
remove this DirectoryIndex index.php!
It sets the index.php behind the url
Use this .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I want to create the adminpanel of my site in codeigniter and I want to manage the controllers of adminpanel in separate folder. I have created a folder "admin" in controllers and a controller "Home.php" in controllers/admin.
Now when I try to access this controller using
http://localhost/web/admin/home/
it gives me 404 error.
I also added $route["admin"] = "admin/home"; in routes.php file.
What am I doing wrong?
EDIT:
MY .htaccess FILE
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Azuaj
RewriteCond $1 !^(index\.php|library|user_guide|robots\.txt)
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond $1 !^(index\.php|library|user_guide|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Add this in your .htaccess file
RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
this should help you..
I know that your problem was already solved through .htaccess, but you may find interesting to know that you could have accomplished your goal with an extension.
https://github.com/ollierattue/codeigniter-multi-level-controller-extension
htaccess code :
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
config file :
$config['base_url'] = 'http://baseurl/apps';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['enable_hooks'] = FALSE;
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;
I am getting "404 page not found " error coming.
when i changed htaccess file
RewriteRule ^(.*)$ index.php?/$1 [L] to RewriteRule ^(.*)$ index.php/$1 [L]
"no input file specifed" error arise.
I have tried several htaccess codes,but still i am getting these issues.
I am using above htaccess codes , for removing index.php from the url.
Try setting
RewriteBase /apps/
in your .htaccess file
In general I use this htaccess, and it never let me down:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Can't use comments yet, so am using the answer box then. You might want to take a look at this question, which got solved and seems like it's almost exactly the same as your issue: CodeIgniter htaccess and URL rewrite issues
edit: If you're using nginx or another webserver, please bear in mind that .htaccess files are not supported on these servers. I too sometimes get 'file input not specified' errors in nginx with some applications. Mostly it is, because those servers don't support .htaccess files. So, please be sure you're using Apache.
RewriteEngine On
RewriteBase /path/learn_ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /path/learn_ci/$1 [L]
Above my .htaccess file how to configure it.
On your .htaccess file put below code.
RewriteEngine On
RewriteBase /path/learn_ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|asset|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
On your application/config/config.php Put below code
$config['base_url'] = 'http://yourdomain.com/';
$config['index_page'] = '';
It will be work for you.
Enjoy...!!! :)
This is what I've been using on most of my CodeIgniter projects, and never had issues.
You need to adjust your RewriteBase. It starts from the root of the web server /www/your_project would be changed to /your_project/ in the htaccess file.
Also, make sure you have mod_rewrite enabled.
How to enable mod_rewrite for Apache 2.2
CodeIgniter htaccess and URL rewrite issues
In addition, you need to remove the index.php from $config['index_page'] = 'index.php' located in config.php in your CodeIgniter installation.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /your_project/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond $1 !^(index\.php|img|font|css|temp|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
this should be your htaccess file on the root folder of your project
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / yourproject
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
and you can remove the index.php from the config.php as: $config['index_page'] = '';
So far I have a fresh install of 2.1.3 and have placed an .htaccess file with:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
in the root directory, same level as application, system, etc.
Edited $config['index_page'] = 'index.php'; to
$config['index_page'] = ''; in application\config\config.php.
Turned on rewrite_module.
Restarted Apache.
But I still end up with a 404 even after trying all the solution, even those in related posts.
Hope this could help this is my htaccess and it works for me.
RewriteEngine On
RewriteBase /codeigniter/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
You need to modify your httpd.conf to enable mod_rewrite and make sure that your webroot directory has AllowOverride set to 'ALL'
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
use this it will work