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

Yad*_*abu 5 php .htaccess codeigniter codeigniter-3

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

这是我的基础

http://cableandmedia.com/demo/
Run Code Online (Sandbox Code Playgroud)

Dee*_*yan 15

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

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

在配置文件中,请使用以下代码更改基本网址: -

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


小智 6

place your htacces file in the root directory and use this following code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Run Code Online (Sandbox Code Playgroud)


Ren*_*cha 5

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

.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?/$1 [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>
Run Code Online (Sandbox Code Playgroud)

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

$config['index_page'] = '';
Run Code Online (Sandbox Code Playgroud)

3. 如果您的服务器是新的 | 您的服务器重写模式被拒绝,而不是打开终端连接您的服务器通过 SSH 键入下面的代码

sudo a2enmod rewrite
sudo service apache2 restart
sudo nano /etc/apache2/apache2.conf
Run Code Online (Sandbox Code Playgroud)

在此之后,请检查AllowOverrideAll或不是

<Directory “/var/www”>
  AllowOverride All
</Directory>
Run Code Online (Sandbox Code Playgroud)