Welcome Guest, Not a member yet? Register   Sign In
failed to remove index.php. lamp on ubuntu 14.04
#1

I am developing a website and trying to remove the notorious index.php but failed.

My OS is ubuntu desktop 14.04. I has installed lamp (apache/2.4.7) and CI successfully.
I put a folder named ciprojects under /var/www/html/.
All my projects are inside the ciprojects folder.
I created mysite1 and  took the application and system folders outside of mysite1 for the sake of security.
I has created .htaccess file inside mysite1 folder and modified the index.php accordingly.

So my files structure is like the below:
  • --/var/www/html/ciprojects/
  •     --application/
  •     --system/
  •     --mysite1/
  •          --index.php
  •          --.htaccess

And inside the .htaccess file is the following code:

--------the below is the code inside .htaccess file ---------------
     RewriteEngine on

     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d

     RewriteRule ^(.*)$ index.php/$1 [L]
--------the above is the code inside .htaccess file ----------------


It works with the index.php.
That means I can access mysite1 via http://localhost/ciprojects/mysite1 successfully.
I also created a new controller named Hello.php.
I can access http://localhost/ciprojects/mysite1/index.php/hello  successfully.

Then I did something more to remove the index.php:

1. sudo a2enmod rewrite
2. sudo service apache2 restart
3. sudo vi /ect/apache2/sites-available/000-default.conf
4. insert below "DocumentRoot /var/www/html" some lines as the following:
    <Directory "/var/www/html">
          AllowOverride All
    </Directory>
5. sudo service apache2 restart.

I then visited http://localhost/ciprojects/mysite1 and http://localhost/ciprojects/mysite1/hello.

I got "500 Internal Server Error" ...

I cannot figure out how to fix the problem, can anyone give me some clue?
Thanks in advance!
Reply
#2

(This post was last modified: 09-22-2015, 04:19 AM by Muzikant.)

Quote:It works with the index.php.
That means I can access mysite1 via http://localhost/ciprojects/mysite1 successfully.
I also created a new controller named Hello.php.
I can access http://localhost/ciprojects/mysite1/index.php/hello  successfully.

You can access http://localhost/ciprojects/mysite1 with or without removed index.php from the URL. You was accessing the Hello controller with index.php in the URL, so you can not be sure, if it was working. But still, also if it was not working, you should get 404 error message, not 500. So the problem could be with the changing default server configuration, not with a CodeIgniter and the .htaccess file.
Reply
#3

Yes, finally I fixed this problem.

The solution:

1. open /etc/apache2/apache2.conf;
2. find the following lines:
  <Directory /var/www/>
          Options Indexes FollowSymLinks
          AllowOverride None
  </Directory>
3. change "AllowOverride None" to "AllowOverride All"
4. restart apache2

Then everything goes smoothly.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB