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

时间:2016-07-20 09:42:46

标签: php .htaccess codeigniter codeigniter-3

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

这是我的基础

http://cableandmedia.com/demo/

6 个答案:

答案 0 :(得分:13)

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

var regex = new Regex(@"[a-zA-Z]+\d+");
var result = regex
               .Matches("AAAA000343BBB343")
               .Cast<Match>()
               .Select(x => x.Value);

// result outputs: "AAAA000343" and "BBB343"

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

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

答案 1 :(得分:4)

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]

答案 2 :(得分:3)

  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>

答案 3 :(得分: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>

答案 4 :(得分:1)

那么,

我在这里做了什么,

我编辑/创建&#34; .htaccess&#34;到这个

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

和&#34; app / config / config.php&#34;

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

和&#34; app / libraries / Template.php&#34;

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

干杯!

答案 5 :(得分:0)

文件:config.php

$config['index_page'] = '';

文件:.htaccess

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

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