404 page not found issue arise when htaccess change in codeigniter - php

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.

Related

codeigniter - what's wrong with my htaccess?

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>

Rewriting index.php in CodeIgniter isn't working

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'] = '';

Codeigniter - .htaccess giving 404 Page Not Found (Files are in a sub-folder)

When I uploaded my file, I uploaded them in shared hosting. The thing is that the files and folders for my codeigniter are in one of those website name folders.
It gives me a 404 error when I visit the site.
My .htaccesss 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>
ErrorDocument 404 index.php
</IfModule>
I really don't know what to do. Any help is appreicated. Thanks.
Edit: When I edit the index.php file and just put something like echo 'Hey'; and delete the .htaccess file, it works fine.
Based on your file structure:
The 404 error may be related to this part:
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
Which means: if the Apache module mod_rewrite.c is not being used or is not present, then all 404's are sent to index.php. If your codeigniter index.php is in your root "web" folder (public_html) then you should write ErrorDocument 404 /index.php instead. If it's in any sub-folders you need for example: /dyar.no/index.php and the remaining rules should also point to the same index.php.
Your current .htaccess works well if you place it near your index.php (the same folder of the root folder of your website).
Besides, an .htaccess is not useful if you don't have meaningful conditions and rules there. The one you have is specifically for codeigniter, which has a system and an application folder.
You can have multiple .htaccess files in your other websites' folders (if you're using codeigniter in more than one of them, copy that .htaccess to those sub-folders e.g.: if dyar.no is using codeigniter copy that .htaccess to that folder).
My suggestion
I noticed that you are also using Wordpress and thus those rules could be changed accordingly... So delete your current root .htaccess file (from the public_html folder) and install BulletProof Security plugin in your wordpress site. Once you do, in the admin dashboard (BPS tab) you just need to click generate secure .htaccess (it generates a strong .htaccess according to your file structure and will cover most of the security issues). After that activate it on the root folder and on the admin folder and you should have all of it covered.
The generated .htaccess can also be a good reference to write other .htaccess you may need.
http://www.askapache.com/htaccess/htaccess.html is one of the best references I found to understand and write .htaccess and here are a few examples.
Hope it helps!
Try this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Add the following in your .htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|folername|uploaded|dist|images|plugins|js|css|cache|robots\.txt)
RewriteRule ^(.*)$ /projectfoldername/index.php/$1 [L]
Note: projectfoldername is your htdocs or project folder name
Just try to change your last line as bellow and let me know please
RewriteRule .* index.php/$0 [PT,L]
Try this Code :
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
try this code for .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
also you need to change config > config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
then your URL like this projectname/contrillerName/functionName/
I suggest using Rewrite base /{your codeigniter folder}/ in .htaccess which works for me.
In .htaccess
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]
In config.php (application/config)
$config['base_url'] = 'http://stackoverflow.com/'; # set this to prevent HOST Injectio.
$config['index_page'] = '';

Having trouble removing index.php from CodeIgniter

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

Codeigniter -> getting 404 error. Simple routes not working

I am an asp.net guy and this is the first time I've dealt with PHP.
Anyhow, I've struggled to migrate an existing site to a new server.
This site is using codeigniter.
When I call http://mydomain/admin
I get a 404 error!
But if I call:
http://mydomain/index.php/admin
it works!
I have placed an .htaccess file on the root:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|scripts|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I have set in the config.php:
$config['index_page'] = '';
My routes.php:
$route['default_controller'] = 'welcome';
$route['scaffolding_trigger'] = '';
I have no idea why it does not work. It must be something very simple I guess...
Thank you!
Did you look through this?:
http://codeigniter.com/wiki/mod_rewrite/
If not, try this one:
<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>
There used to be one from Jamie Rumbelow I used to use a bit, but it's not on his blog anymore... I'm used to nginx now though, so my favorite configuration won't work for you.
Your .htaccess file didn't work for me either. But it worked once I changed the rewrite rule to this :
RewriteRule ^(.*)$ index.php/$1 [L]
I just removed the slash at the beginning.
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
1º - Create an .htaccess file in the root you're CodeIgniter project.
2º - In the created .htaccess file put the code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
try adding RewriteBase / in .htaccess
$default_controller = "home";
$language_alias = array('gr','fr');
$controller_exceptions = array('signup');
$route['default_controller'] = $default_controller;
$route["^(".implode('|', $language_alias).")/(".implode('|', $controller_exceptions).")(.*)"] = '$2';
$route["^(".implode('|', $language_alias).")?/(.*)"] = $default_controller.'/$2';
$route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
foreach($language_alias as $language)
$route[$language] = $default_controller.'/index';
$route['404_override'] = '';

Categories