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

问题描述 投票:0回答:8

我正在 CodeIgniter 3 中做一个项目。我需要从 url 中删除

index.php
。为此,请帮助我获取 CodeIgniter 3 的
.htaccess
文件以及放置此文件的位置。

这是我的基本网址

http://cableandmedia.com/demo/
php .htaccess codeigniter codeigniter-3
8个回答
23
投票

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

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

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

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

14
投票

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

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

13
投票
  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>

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

之后请检查

AllowOverride
是否为
All

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

2
投票

文件:config.php

$config['index_page'] = '';

文件:.htaccess

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

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


1
投票

在您的

config.php
中进行以下更改。

$config['index_page'] = '';

并在主项目目录中添加

.htaccess
文件,内容如下

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

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

1
投票

嗯,

这是我所做的,

我为此编辑/创建了“.htaccess”

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [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
投票
  1. 在项目根目录创建一个 .htaccess 文件并添加以下代码。
RewriteEngine on   
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
  1. 在 config.php 中进行以下更改。

$config['base_url']    = 'PUT YOUR BASE URL HERE';    
$config['index_page'] = '';

0
投票
 1. open your .htaccess file present in the root and add the below code :-
RewriteEngine On
RewriteBase /demo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]


2. Now in your config.php file 
 update this line of code :- $config['index_page'] = '';
© www.soinside.com 2019 - 2024. All rights reserved.