CodeIgniter removing index.php from url

前端 未结 30 1416
[愿得一人]
[愿得一人] 2020-11-21 11:51

My current urls look like this [mysite]index.php/[rest of the slug].
I want to strip index.php from these urls.

mod_rewrite

30条回答
  •  天涯浪人
    2020-11-21 12:03

    Well these all answers are good but for a newbie(which is do first time) these are confusing. There are other htaccess files which is reside in controller but we have to edit or add the htaccess in main project folder.

    This is your codeigniter folder, where file resides like application,system,assets,uploads etc.

    Your_project_folder/
    application/
    assets/
    cgi-bin/
    system/
    .htaccess---->(Edit this file if not exist than create it)
    index.php
    

    Change this file as written below:

    
      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/
      # Otherwise /
      RewriteBase /
      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: Anand Pandey
      ErrorDocument 404 /index.php
    
    

    and yes of course you need to change two lines of code in the application/config/config.php

    //find the below code   
    $config['index_page'] = "index.php";
    $config['uri_protocol'] ="AUTO" 
    //replace with the below code
    $config['index_page'] = "";
    $config['uri_protocol'] = "REQUEST_URI";
    

提交回复
热议问题