Paritosh Paritosh - 3 months ago 9
PHP Question

Removing index.php from URL in CodeIgniter on Mandriva

I developed a project which uses CodeIgniter on Windows OS. The project works fine on XAMPP (Windows) and Linux hosting server (updated .htaccess on server to work). I want to use Open Mandriva for development purpose. If I run the controller using index.php, it works.

I tried many .htaccess rules examples, links. But controller is not loading.

I tried: Cannot remove index.php from CodeIgniter URL, CodeIgniter removing index.php from url and
this external link, and many other links.

.htaccess code on Windows machine

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]


.htaccess code on Linux hosting server

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]


Both are not working on Open Mandriva.

.htaccess path

/srv/www/html/ci/


The page gives:


404 error, and Object not found!


The file system path to my project is

/srv/www/html/ci/application/controllers/


and on browser:

localhost/ci/branch


Project works if I add index.php like

localhost/ci/index.php/branch


Is it having any relation with http server config? Do I need to install any package. Also I tried some commands for apache rewrite engine. But I get error as unknown command.

Answer

Check if rewrite engine is enabled.

If not, enable rewrite engine and restart server.

sudo a2enmod rewrite
sudo service apache2 restart

Go to

/etc/httpd/conf/httpd.conf - for Mandriva
/etc/apache2/apache2.conf  - for Ubuntu

Change AllowOverride None to AllowOverride All

Code block:

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

Restart Apache(httpd) service.

No changes required in config.php or anywhere else.

.htaccess code:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]