删除index.php无效

时间:2011-04-11 17:26:04

标签: php .htaccess url codeigniter mod-rewrite

我有这个site,当你点击中心的go时,我会把它转到这个网址

 http://dev.posnation.com/welcome/redirect

这不是欢迎控制器和重定向操作的正确页面。正确的网址是

 http://dev.posnation.com/index.php/welcome/redirect

我的codeigniter结构就像这样

-rw-r--r--@  1 tamer  staff   225 Apr 11 13:09 .htaccess
drwxr-xr-x@ 18 tamer  staff   612 Apr  8 17:26 application
drwxr-xr-x  11 tamer  staff   374 Apr 11 09:46 css
drwxr-xr-x@  6 tamer  staff   204 Mar 24 14:20 graphics
drwxr-xr-x  17 tamer  staff   578 Apr 11 09:54 js
drwxr-xr-x@ 10 tamer  staff   340 Apr  7 12:20 system
drwxr-xr-x@ 16 tamer  staff   544 Apr  7 12:20 user_guide

将index.php输出一个目录

我的.htaccess由此构成

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

任何想法

4 个答案:

答案 0 :(得分:2)

你在RewriteCond之后错过了一条Rewrite规则。尝试

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

答案 1 :(得分:1)

Codeigniter Wiki提供以下狙击:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    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]
</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>

在您的配置中,请相应更改以下变量:

config['uri_protocol'] = 'QUERY_STRING'; //set to QUERY_STRING

$config['index_page'] = ""; //Remove index.php

确保加载了Apache mod_rewrite模块(仅当上面引发404时)。

http://codeigniter.com/wiki/mod_rewrite/

可能存在更多问题

答案 2 :(得分:0)

它有时会让人感到困惑。尝试将其添加为最后一行

 RewriteRule ^(.*)$ ./index.php?$1 [L,QSA] 

答案 3 :(得分:0)

我遇到了类似的问题。确保你获得了RewriteRule。不同的方法也需要不同的方法来捕获变量。我见过两个,其中一个基本上将$ _GET数组变量应用于示例中给出的url变量。

RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

RewriteRule ^(.*)$ ./index.php?url=$1 [L,QSA]

你可以分别抓住'm:

echo $_SERVER['PATH_INFO'];

echo $_GET['url'];

CodeIgniter使用index.php?/ $ 1。这给我带来了问题。