简体   繁体   中英

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.

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]

Please try the following:

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

Then, in config.php :

$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";

Please ensure that your .htaccess is located in the same directory as your index.php .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM