【问题标题】:Get rid of index.php/ on codeigniter在 codeigniter 上摆脱 index.php/
【发布时间】:2015-08-11 19:09:16
【问题描述】:

我的.htaccess 文件中有这个

<IfModule mod_rewrite.c>    
Options +FollowSymLinks     
Options -MultiViews

RewriteEngine On    
RewriteBase /   
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d     
RewriteRule ^.+$ /index.php [L]
</IfModule>

我的网站在index.php 中显示了我所有网络文件的文件。我试图摆脱必须输入mysite/index.php/filename 并直接转到mysite/filename

我的网址是http://local-news.today/subscribe。当我使用这个地址local-news.today/index.php/subscribe 时它可以工作,它显示了订阅功能上的内容。

我的网站托管在 godaddy。我也在使用codeigniter。任何帮助将不胜感激。

【问题讨论】:

  • 确保$config['index_page'] = ''config.php 中。
  • 是的,我的已经设置好了。

标签: php .htaccess codeigniter mod-rewrite


【解决方案1】:

我在我的 htaccess 文件中完成了以下操作:

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

这对我有用。

【讨论】:

    【解决方案2】:

    将以下代码放入.htaccess

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

    并在 application/config/config.php 中找到以下行

    $config['index_page'] = "index.php"
    

    并用以下代码替换它

    $config['index_page'] = ""
    

    【讨论】:

    • local-news.today/subscribe/ 给我“没有指定输入文件”。空白页。当我尝试弥补一些无效目录时得到相同的结果。
    • 你能解释一下这个问题吗?
    【解决方案3】:

    对“codeigniter mod_rewrite htaccess”的简单搜索显示this gist

    <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/
      RewriteBase /
      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>
    

    所以基本上你的重写规则有点错误。你需要类似的东西

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

    这是什么意思? ^(.*)$ 将所有内容 ((.*)) 从开头 (^) 到结尾 ($) 进行匹配,并使用 $1 将其附加到 index.php?/

    在您的示例中,您忘记将其附加到网址的末尾...

    【讨论】:

      【解决方案4】:

      根据我的经验,在共享主机上,您经常需要使用.htaccess 文件。这个通常对我有用:

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

      但您会注意到,这里的最后一行与其他答案不同,? 位于/ 之后,而不是它之前(或根本没有)。所以试试这个作为基础.htaccess,然后在必要时修改最后一行。可能还需要删除RewriteBase \ 行。

      【讨论】:

        【解决方案5】:

        我总是使用这个,它就像一个魅力:

        <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
            #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.
        
            ErrorDocument 404 /index.php
        </IfModule>
        

        【讨论】:

          猜你喜欢
          • 2014-07-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-03-12
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多