从URL中删除index.php - Codeigniter 2

Pau*_*aul 29 php .htaccess codeigniter

我无法从Codeigniter中的URL中删除index.php.我用Codeigniter 1.7创建了一些网站,我使用的.htaccess代码在2中不起作用.

我试过用

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

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

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]

</IfModule>
Run Code Online (Sandbox Code Playgroud)

我也尝试过没有RewriteBase/in.

我已将$ config ['uri_protocol']更改为REQUEST_URI和QUERY_STRING而没有.

我设置了$ config ['index_page'] ="";

文件结构是192.168.0.130/(site)/所以它必须返回到服务器的根目录,找不到index.php文件.

我所做的所有控制器都可以通过192.168.0.130/(site)/index.php/testcontroller来实现.

谢谢.

如果之前有人问过这个道歉 - 我已经看过并尝试过我能看到的东西.

编辑:

我还应该补充一点,我将默认文件夹更改为

应用

CI-2.0

的index.php

并将index.php中的路径更改为正确.

WNR*_*erg 23

尝试你发布的第一个代码块,但不要使用/index.php而不是/(site)/index.php(用你的站点文件夹命名的obv替换(站点)).

  • 这可能听起来像一个愚蠢的问题,但你最初测试的服务器是否启用了mod_rewrite? (2认同)

小智 15

这对我有用:

  1. 创建您的htaccess文件
  2. 将$ config ['index_page']设置为空(config.php)
  3. string Set $ config ['uri_protocol'] ='REQUEST_URI'; (config.php的)

这是我的htaccess文件:

Options -Indexes
Options +FollowSymLinks
Run Code Online (Sandbox Code Playgroud)

RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#When your application folder isn't in the system folder

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php

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

# 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
Run Code Online (Sandbox Code Playgroud)

资源:

http://taggedzi.com/articles/display/codeigniter-2-htaccess-and-friendly-urls