.htaccess Codeigniter-删除index.php

.htaccess Codeigniter-删除index.php,.htaccess,codeigniter-2,codeigniter-url,.htaccess,Codeigniter 2,Codeigniter Url,我已经试了好几个小时,没能成功。到处寻找答案,但似乎没有什么能解决我的问题 我甚至尝试了这里描述的解决方案:。一点运气都没有 我已将配置['index_page']设置为“” My.htaccess位于根文件夹(sys和app文件夹所在的位置)上,其编写方式如下: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0

我已经试了好几个小时,没能成功。到处寻找答案,但似乎没有什么能解决我的问题

我甚至尝试了这里描述的解决方案:。一点运气都没有

我已将配置['index_page']设置为“”

My.htaccess位于根文件夹(sys和app文件夹所在的位置)上,其编写方式如下:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 
RewriteBase /                                 # make sure we always rewrite from within the root directory

RewriteCond %{REQUEST_FILENAME} !-f           # make sure the request is not to an existing file
RewriteCond %{REQUEST_FILENAME} !-d           # nor an existing directory
RewriteCond %{REQUEST_FILENAME} !^index\.php  # make sure we do only interpret requests that DO NOT start with index.php
RewriteRule ^(.*)$ index.php/$1 [L,QSA]       # interpret request as if it were to index.php/...

# make sure we do only interpret requests that DO start with index.php
RewriteRule ^index\.php/(.*)$ $1 [L,R,QSA]    # redirect user to new URL, which will be handled by the first rewriterule
不过,我访问控制器方法的唯一方法是使用url中该死的index.php。 是的,我的apacheconf启用了mod rewrite

任何帮助都会非常好

编辑

我会再补充一些信息,也许是相关的

  • 我正在使用ZendServer
  • 我现在在localhost工作

我没有使用代码点火器的经验,但如果我理解正确,您正试图向用户提供类似/index.php/my-page的服务,而不需要用户在其前面添加index.php

如果我是对的,你可以试试这样:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 
RewriteBase /                                 # make sure we always rewrite from within the root directory

RewriteCond %{REQUEST_FILENAME} !-f           # make sure the request is not to an existing file
RewriteCond %{REQUEST_FILENAME} !-d           # nor an existing directory
RewriteCond %{REQUEST_FILENAME} !^index\.php  # make sure we do only interpret requests that DO NOT start with index.php
RewriteRule ^(.*)$ index.php/$1 [L,QSA]       # interpret request as if it were to index.php/...

# make sure we do only interpret requests that DO start with index.php
RewriteRule ^index\.php/(.*)$ $1 [L,R,QSA]    # redirect user to new URL, which will be handled by the first rewriterule

让我知道这是否有效

我没有使用CodeIgniter的经验,但如果我理解正确,您正在尝试向用户提供类似/index.php/my-page的服务,而不需要用户在其中预先添加index.php

RewriteEngine On
RewriteBase /yourdirectoryname/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
如果我是对的,你可以试试这样:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 
RewriteBase /                                 # make sure we always rewrite from within the root directory

RewriteCond %{REQUEST_FILENAME} !-f           # make sure the request is not to an existing file
RewriteCond %{REQUEST_FILENAME} !-d           # nor an existing directory
RewriteCond %{REQUEST_FILENAME} !^index\.php  # make sure we do only interpret requests that DO NOT start with index.php
RewriteRule ^(.*)$ index.php/$1 [L,QSA]       # interpret request as if it were to index.php/...

# make sure we do only interpret requests that DO start with index.php
RewriteRule ^index\.php/(.*)$ $1 [L,R,QSA]    # redirect user to new URL, which will be handled by the first rewriterule
让我知道这是否有效

RewriteEngine On
RewriteBase /yourdirectoryname/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
我在ZendServer上没有任何经验,但今晚我在使用xampp(不使用ZendServer)的localhost上也遇到了这个问题,并最终解决了这个问题:

  • 检查您的httpd.conf,并确保“LoadModule rewrite\u modules/mod\u rewrite.so”行没有注释
  • 打开config.php,设置$config['base\u url']='http://localhost/yourdirectoryname/"
  • 仍然在config.php中,设置$config['index_page']=''
  • 在与index.php相同的目录下创建.htaccess文件(在我的例子中是htdocs/yourdirectoryname)
  • 该.htaccess文件的内容如上所示
  • 我在ZendServer上没有任何经验,但今晚我在使用xampp(不使用ZendServer)的localhost上也遇到了这个问题,并最终解决了这个问题:

  • 检查您的httpd.conf,并确保“LoadModule rewrite\u modules/mod\u rewrite.so”行没有注释
  • 打开config.php,设置$config['base\u url']='http://localhost/yourdirectoryname/"
  • 仍然在config.php中,设置$config['index_page']=''
  • 在与index.php相同的目录下创建.htaccess文件(在我的例子中是htdocs/yourdirectoryname)
  • 该.htaccess文件的内容如上所示

  • 试试这个,我在任何地方的许多主机上都使用过,请检查:

    RewriteEngine On
    RewriteBase /yoursitedirectory/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
    如果不足够,请转到
    config.php
    文件并搜索以下行:

    |--------------------------------------------------------------------------
    | URI PROTOCOL
    |--------------------------------------------------------------------------
    |
    | This item determines which server global should be used to retrieve the
    | URI string.  The default setting of 'AUTO' works for most servers.
    | If your links do not seem to work, try one of the other delicious flavors:
    |
    | 'AUTO'            Default - auto detects
    | 'PATH_INFO'       Uses the PATH_INFO
    | 'QUERY_STRING'    Uses the QUERY_STRING
    | 'REQUEST_URI'     Uses the REQUEST_URI
    | 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO
    |
    */
    $config['uri_protocol'] = 'AUTO';
    

    我使用的是
    AUTO
    ,但您可能需要将其切换到
    REQUEST\u URI
    QUERY\u STRING
    ,试试这个,我在任何地方的许多主机上都使用过,请检查:

    RewriteEngine On
    RewriteBase /yoursitedirectory/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
    如果不足够,请转到
    config.php
    文件并搜索以下行:

    |--------------------------------------------------------------------------
    | URI PROTOCOL
    |--------------------------------------------------------------------------
    |
    | This item determines which server global should be used to retrieve the
    | URI string.  The default setting of 'AUTO' works for most servers.
    | If your links do not seem to work, try one of the other delicious flavors:
    |
    | 'AUTO'            Default - auto detects
    | 'PATH_INFO'       Uses the PATH_INFO
    | 'QUERY_STRING'    Uses the QUERY_STRING
    | 'REQUEST_URI'     Uses the REQUEST_URI
    | 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO
    |
    */
    $config['uri_protocol'] = 'AUTO';
    

    我使用的是
    AUTO
    ,但您可能需要将其切换到
    REQUEST\u URI
    QUERY\u STRING
    ,试试看,我终于解决了这个问题。感谢所有的答案,特别感谢@ddanurwenda。他的重写规则是唯一解决我问题的规则

    我忽略了一个Apache配置:我更改了这一行(来自httpd.conf):

    
    选项如下符号链接
    不允许超限
    命令拒绝,允许
    全盘否定
    
    对下列事项:

    <Directory />
        Options FollowSymLinks
        AllowOverride All
        Order deny,allow
        Deny from all
        Satisfy all
    </Directory>
    
    
    选项如下符号链接
    允许超越所有
    命令拒绝,允许
    全盘否定
    满足所有
    

    该配置使我的htaccess文件无法读取。

    我终于设法解决了这个问题。感谢所有的答案,特别感谢@ddanurwenda。他的重写规则是唯一解决我问题的规则

    我忽略了一个Apache配置:我更改了这一行(来自httpd.conf):

    
    选项如下符号链接
    不允许超限
    命令拒绝,允许
    全盘否定
    
    对下列事项:

    <Directory />
        Options FollowSymLinks
        AllowOverride All
        Order deny,allow
        Deny from all
        Satisfy all
    </Directory>
    
    
    选项如下符号链接
    允许超越所有
    命令拒绝,允许
    全盘否定
    满足所有
    

    该配置阻止读取我的htaccess文件。

    这就是我使用和工作的内容。 在.htaccess中使用此代码

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* website/index.php/$0 [PT,L] 
    
    只需确保.htaccess在您的根文件夹中。(即:xampp/htdocs)

    然后在config.php(application\config)中替换
    config['index\u page']='index.php'

    config['index\u page']=''

    这就是我使用和工作的东西。 在.htaccess中使用此代码

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* website/index.php/$0 [PT,L] 
    
    只需确保.htaccess在您的根文件夹中。(即:xampp/htdocs)

    然后在config.php(application\config)中替换
    config['index\u page']='index.php'

    config['index\u page']=''

    我也有同样的问题,我到处找,但找不到任何有效的方法,所以我暂时创建了一个钩子,直到找到一个合适的解决方案:if(strstrstr($_-SERVER['REQUEST\u-URI'],'index.php'):$url=str\u-replace('index.php/,',$_-SERVER['REQUEST\u-URI']);标题(“HTTP/1.1 301永久移动”)$url=ltrim($url,“/”);标题(“位置:);退出();endif;我会继续问这个问题,看看是否有人帮忙。很好,我会在有时间的时候试试。但我更愿意使用htaccess文件。我只是想知道wtf在这里不起作用。你试图加载的url是什么?我也有同样的问题,我到处都找了,但找不到任何有效的,所以我创建了一个hook暂时,直到我找到一个合适的解决方案:if(strstrstr($_SERVER['REQUEST_URI'],'index.php'):$url=str_replace('index.php/','',$_SERVER['REQUEST_URI']);header(“HTTP/1.1 301永久移动”);$url=ltrim('url',/');header(“位置:);退出();endif;我会跟着这个问题,看看是否有人能帮上忙。很好,等我有时间的时候我会试试的。但我会