How do I write a .htaccess file to make CodeIgniters URL routing work?

后端 未结 9 1136
死守一世寂寞
死守一世寂寞 2020-12-01 01:13

I\'m running a LAMP environment with CodeIgniter. I want to be able to use its URL pattern, like, http://localhost/controller/function/ID, but by default it has

9条回答
  •  攒了一身酷
    2020-12-01 01:33

    Had some problems with finding where to change the "AllowOverRide All".

    From this guide I found the (default) file.

    Remove Index.php CodeIgniter URL On Ubuntu

    1. Preliminary Note. I'm running all the steps in this tutorial with root privileges, so make sure you're logged in as root:

      sudo su
      
    2. Enable mod_rewrite module on apache. First enable the module as follows:

      a2enmod rewrite
      

      Change all occurrence of "AllowOverRide None" to "AllowOverRide All". Basically all "None" to "All" in the following file:

       gedit **/etc/apache2/sites-available/default**
      

      Restart Apache:

      /etc/init.d/apache2 restart
      
    3. Open file config.php on CodeIgniter (application\config). Remove index.php on $config['index_page'] = "index.php";

      $config['index_page'] = "";
      
    4. Make file .htaccess on CodeIgniter root directory. Fill the file with this code :

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

    Now Index.php on CodeIgniter URL disappear

提交回复
热议问题