0

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.

Community
  • 1
  • 1
Paritosh
  • 2,097
  • 3
  • 30
  • 42
  • 1
    Please could you share the current content of your `.htaccess` file? This will help us to help you. – Mike Rockétt Feb 15 '15 at 12:10
  • Where are your files stored? At the document root? And why do you need to check `/system.*`? – Mike Rockétt Feb 15 '15 at 12:32
  • .htaccess is stored at same level of application or system folder. Actually I am not having any knowledge about htaccess rules. The code worked so I kept it for respective platforms. – Paritosh Feb 15 '15 at 12:35
  • Off-topic: I recently commented on one of your answers, which you can copy-and-pasted from [another of your answers](http://stackoverflow.com/a/30026152/472495). I think deleting the copy was the correct course of action, but why did you delete the original? That was fine: if that itself was not a copy, I suggest you reinstate it. – halfer May 06 '15 at 10:42

2 Answers2

2

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]
Community
  • 1
  • 1
Paritosh
  • 2,097
  • 3
  • 30
  • 42
1

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.

Mike Rockétt
  • 8,947
  • 4
  • 45
  • 81
  • Please could you share what errors you are getting? What happens when you try to access `example.com/your-controller`? – Mike Rockétt Feb 15 '15 at 12:46
  • 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, http://localhost/ci/branch/ Project works if I add index.php like http://localhost/ci/index.php/branch/ – Paritosh Feb 15 '15 at 12:51
  • Try this http://stackoverflow.com/questions/28517126/codeigniter-htaccess-and-url-redirect-issues/28517329#28517329 –  Feb 15 '15 at 12:51
  • The path to your project should be `/srv/www/html/ci/` as that is the CodeIgniter root. That is where your `.htaccess` file should be stored. – Mike Rockétt Feb 15 '15 at 13:00
  • Yes. The file is there. – Paritosh Feb 15 '15 at 13:02
  • Please see my amended answer - I have added `RewriteBase /ci/` – Mike Rockétt Feb 15 '15 at 13:04
  • Then I'm afraid I've tried everything I can think of right now... Good luck! – Mike Rockétt Feb 15 '15 at 13:25
  • 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. – Paritosh Feb 15 '15 at 13:47
  • I'm afraid the only thing I can think of is that your `mod_rewrite` may not be enabled... – Mike Rockétt Feb 15 '15 at 15:20
  • Ah, right! (Always seems to be the last thing I check for.) Well done :) – Mike Rockétt Feb 15 '15 at 17:14