从 CodeIgniter 3 中的 url 中删除 index.php

Remove index.php from url in CodeIgniter 3

我正在 CodeIgniter 3 中做一个项目。我需要从 url 中删除 index.php。为此,请帮助我获取 CodeIgniter 3 的 .htaccess 文件以及放置此文件的位置。

这是我的基地url

http://cableandmedia.com/demo/

将您的 .htaccess 文件放在根目录中并使用以下代码:

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

在您的 config.php 中进行以下更改。

$config['index_page'] = '';

并在主项目目录中添加.htaccess文件,内容如下

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

<Files "index.php">
AcceptPathInfo On
</Files>

使用以下代码更新您的 htaccess 文件

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

在配置文件中,请使用以下代码更改基础 url:-

$root  = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url']    = $root;

文件: config.php

$config['index_page'] = '';

文件:.htaccess

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

RewriteEngine 允许您重写 URL 进入您的服务器的请求,它基于正则表达式解析器。

嗯,

这是我所做的,

我edited/create“.htaccess”到这个

RewriteEngine on
RewriteCond  !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L,QSA] 

和"app/config/config.php"

$config['base_url'] = '';
$config['uri_protocol'] = 'AUTO';

和"app/libraries/Template.php"

define("PATH", base_url()."index.php/");
define("BASE", base_url());

干杯!

  1. 在项目root处创建.htaccess文件

.htaccess

<IfModule mod_rewrite.c>
  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?/ [L]
</IfModule>

<IfModule !mod_rewrite.c>
  # 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
</IfModule>

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin: "*"
</IfModule>

2。删除 root/application/config/config.php

处的 index.php
$config['index_page'] = '';

3。如果您的服务器是新的 |你的服务器重写模式被拒绝打开终端通过 SSH 类型连接你的服务器代码

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

之后请检查AllowOverrideAll还是

<Directory “/var/www”>
  AllowOverride All
</Directory>