Codeigniter site was not working in live server - .htaccess

Can someone help me,
My site was working fine in staging server and I moved the site live server where I am getting HTTP ERROR 500.
My htaccess file is
<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>
The same htaccess file was there in both the servers. mod_rewrite was enabled and everything was fine from server side. Can someone help me what can be the issue

Not exactly an answer but too large for a comment:
switch (ENVIRONMENT) {
case 'development':
error_reporting(~E_DEPRECATED);
ini_set('display_errors', 1);
break;
case 'testing':
case 'production':
error_reporting(~E_DEPRECATED);
ini_set('display_errors', 1);
break;
default:
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'The application environment is not set correctly.';
exit(1); // EXIT_ERROR
}
Change production to have the same error_reporting as development so you will get the errors instead of seeing a generic 500 page.
I don't believe you .htaccess file is at fault here as you wouuld get a 400 rather than a 500 (internal server error).

you can try this:
upload htaccess file in root
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options -Indexes
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

Related

My htaccess rule not wroking for a project on live server (htaccess is inside the folder)

What i am trying to do:
On my server for a particular project I want to write URL-REWriting rules through htaccess (remove .php or .html extension from URL).
My Site Url:
http://enacteservices.com/EpcGroup/
And:
http://www.enacteservices.com/EpcGroup/contact
Now if you look second URL .php extension is removed perfectly but it shows Page Not Found while page is there.
If I wrote there: http://www.enacteservices.com/EpcGroup/contact.php
It start working.
What I have tried to write in .htaccess (this file is inside my folder):
First
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /EpcGroup/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
#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 ^(.*)$ admin/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>
Second: Added (EpcGroup/):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /EpcGroup/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
#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 ^(.*)$ EpcGroup/admin/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 ^(.*)$ EpcGroup/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 ^(.*)$ EpcGroup/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 EpcGroup/index.php
</IfModule>
But it's not working.
One .htaccess which on my root have this coding:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Based on recent comment, update the root .htaccess to:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/EpcGroup [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
and the one inside your EpcGroup directory to:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /EpcGroup/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^[^\.]+$ $0.php [NC,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^[^\.]+$ $0.html [NC,L]
#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 ^(.*)$ admin/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>

.htaccess control remove from a folder

I have a codeigniter project running on root folder. In the same server on a folder called ems2 another project is running. But because of the root .htaccess of codeigniter project, the ems2 project is not working. How can I remove .htaccess control from ems2 folder?
My .htaccess file on root has following code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#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} ^codeigniter.*
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} ^uz\-mi.*
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
RewriteCond $1 !^(index\.php|images|css|style|uploads|js|robots\.txt)
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>
RewriteCond %{HTTP_HOST} ^encg\.ae$ [OR]
RewriteCond %{HTTP_HOST} ^www\.encg\.ae$
RewriteRule ^/?$ "http\:\/\/www\.abc\.com\/encg" [R=301,L]
RewriteCond %{HTTP_HOST} ^ncg\.ae$ [OR]
RewriteCond %{HTTP_HOST} ^www\.ncg\.ae$
RewriteRule ^/?$ "http\:\/\/www\.abc\.com\/encg" [R=301,L]
You can add a new, simple .htaccess file to the ems2 project folder with a "NOP" content to stop processing the .htaccess from the parent folder.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
</IfModule>

How to remove application folder name in code igniter

<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} ^main.*
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]
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.domain.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,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>
Currently the URLs are showing up as http://www.domain.com/main/home but I would rather have it appear as http://www.domain.com/home. How can I change that?
Should just be these lines (not positive about the first, the second for sure though):
RewriteRule (.*) http://www.domain.com/main/$1 [R=301,L]
RewriteRule ^(.*)$ /main/index.php?/$1 [L]
Try adding this near the top of your rules:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?main/(.*)$ /$1 [L,R]
Codeigniter has built in routes which is helpful in your situtation. In routes.php :
$route['home'] = 'main/home';

Codeigniter htaccess index.php site down

Codeigniter htaccess started problem suddenly even when no changes were made to any files. I can access
www.mysite.com/index.php/controller/method
but when I access
www.mysite.com/controller/method
it gives a general 404, not a codeigniter 404. Any help is appreciated. The site is down.
Here is my present 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]
#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
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
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>
In this case i'm 100% sure your mod_rewrite is not working properly.Also make sure your .htacess file is in your root directory. A have this one working properly on my server may be this will help you :-
# rewrite rules
RewriteEngine On
# ditch index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

mod-rewrite problem in codeigniter

I'm developing a site on my localhost (Usbwebserver application). I'm using CodeIgniter framework:
url is "http://localhost/daniel/index.php"
with the following options:
config/routs:
$route['default_controller'] = "site";
config/config:
$config['base_url'] = "http://localhost/daniel";
$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";
I've tried the following .htaccess code:
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]
#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]
# 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
I want to remove index.php and to load my default controller with http://localhost/daniel.
Any suggestions?
Try:
RewriteRule ^(.*)$ /daniel/index.php?/$1 [L]
I used the hataccess from the codigniter wiki(the same that I had above):
RewriteEngine On
RewriteBase /
# Removes the "/" at the end
RewriteRule (.+)/$ /$1 [L,R]
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ daniel/index.php?/$1 [L]
# 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
With all the same option, only $config['uri_protocol'] = "AUTO"(instead of URI_PROTOCOL) and somehow it began to work (and I have the aplication folder outside of the system folder)
Thank You all who kindly replied me!

Resources