Codeigniter从URL本地主机:82 / project中删除index.php

时间:2018-09-26 21:06:24

标签: php .htaccess codeigniter codeigniter-htaccess

我有URL

  

http://localhost:82/project/index.php/home

我想从上面的网址中删除index.php。

  

像这样:http://localhost:82/project/home

我用了很多解决方法

1)我已从config.php文件中删除index.php:

$config['index_page'] = '';

2)在config.php文件中更改“ uri_protocol”:

$config['uri_protocol'] = 'REQUEST_URI';

我的htaccess:

RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

有人在这里解决我的问题吗?预先感谢。

4 个答案:

答案 0 :(得分:1)

如果您使用的是Apache服务器,则必须启用mod_rewrite。然后使用下面的代码修改.htaccess文件。

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

有关更多信息,请访问here

尝试类似的问题here

答案 1 :(得分:1)

使用此 Codeigniter .htaccess文件并将其安装到您的根应用程序。

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

喜欢这个...

project_name
    -application
    -assets
    -system
    -user_guide
    -.htaccess // like this one

答案 2 :(得分:1)

尝试使用此

RewriteEngine on
#RewriteBase /project/
RewriteCond $1 !^(index\.php|images|admin|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|admin|robots\.txt)
RewriteRule .* index.php/$0 [PT,L]

我用它并在我身上工作。 谢谢

答案 3 :(得分:1)

在配置中将基本URL设置为

$config['base_url'] = 'http://localhost:82/project/'

在您的.htaccess中,尝试一下,我已经在我的CI项目中使用了它。

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

将此文件放在您的项目文件夹中。

Folder structure

相关问题