Remove index.php from url in CodeIgniter 3

前端 未结 6 1568
死守一世寂寞
死守一世寂寞 2020-12-14 13:42

I am doing a project in CodeIgniter 3. I need to remove index.php from url. For that help me to get .htaccess file for CodeIgniter 3 and also where

6条回答
  •  囚心锁ツ
    2020-12-14 14:24

    1. Create .htaccess file at root of the project

    .htaccess

    
      RewriteEngine On
      # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
      #  slashes.
      # If your page resides at
      #  http://www.example.com/mypage/test1
      # then use
      # RewriteBase /mypage/test1/
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [L]
    
    
    
      # If we don't have mod_rewrite installed, all 404's
      # can be sent to index.php, and everything works as normal.
      # Submitted by: ElliotHaughin
        ErrorDocument 404 /index.php
    
    
    
        Header set Access-Control-Allow-Origin: "*"
    
    

    2. Remove index.php at the root/application/config/config.php

    $config['index_page'] = '';
    

    3. If your server is new | your server rewrite mode was denied than Open Terminal Connect Your Server Via SSH Type Below Code

    sudo a2enmod rewrite
    sudo service apache2 restart
    sudo nano /etc/apache2/apache2.conf
    

    After that please check AllowOverride Is All or not

    
      AllowOverride All
    
    

提交回复
热议问题