I am working on a web application built using php in codeigniter. Everything works fine in localhost. However .htaccess file is being ignored by my live server (RH7.1 Apache 2.4) despite Overide All in httpd.conf. I have restarted the Apache Service but nothing is working. Any idea what can be wrong?


RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]


strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false

returns 1.

httpd.conf values:

# Further relax access to the default document root:
<Directory "/var/www/html">
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    Options Indexes FollowSymLinks

    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    AllowOverride All

    # Controls who can get stuff from this server.
    Require all granted

. . . . .

# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
<Files ".ht*">
    Require all denied

Seems like issue was with .htaccess content. I replaced it with:

<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 !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

and it started working fine. I am sort of new in this. Can anyone tell me why it was not working before and why it is working with new .htaccess file content?

| improve this answer | |

Can anyone tell me why it was not working before and why it is working with new .htaccess file content?

RewriteRule ^(.*)$ ./index.php/$1 [L]

Your original .htaccess file passes the requested URL-path as part of additional pathname information on the URL (aka PATH_INFO). eg. /index.php/foo/bar.

To enable this in Codeigniter you'd probably have to explicitly set this in config.php:

$config['uri_protocol']  = 'PATH_INFO';

However, note that PATH_INFO could also be disabled in your Apache server config with the AcceptPathInfo directive.

RewriteRule ^(.*)$ index.php?/$1 [L]

Whereas your "new" .htaccess file passes the requested URL-path as part of the query string instead. eg. /index.php?/foo/bar (note the additional ?). It's possible that this is Codeigniter's default configuration and will always work, regardless of the server config.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.