【问题标题】:Removing index.php from CodeIgniter URL in a sub-directory of the web root从 Web 根目录的子目录中的 CodeIgniter URL 中删除 index.php
【发布时间】:2012-07-16 15:05:55
【问题描述】:

我已经尝试了几个小时来实现这一目标!

我的 codeigniter 应用程序位于 webroot 的子文件夹中,该子文件夹称为“Tat”。

我在 codeigniter 文件夹(应用程序和系统文件夹旁边)中使用以下 .htaccess 文件:

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

如果我访问: 127.0.0.1/Tat/ - 我去 CodeIgniter 应用,很好。

如果我访问: 127.0.0.1/Tat/index.php/register - 我去我的 CI 应用程序的注册页面(不想要 index.php 那里!)

如果我访问: 127.0.0.1/Tat/register - 它将我带到整个服务器的网络根目录!我想让它带我到注册页面!

我不知道该怎么做!

值得一提的是: * 我的基本 URL 已设置:$config['base_url'] = 'http://127.0.0.1:5678/Tat'; * 我的索引页已设置:$config['index_page'] = ''; * 我完全控制服务器,它是在 Ubuntu Precise 64 上运行 Apache2 的开发服务器。

如果有人能指出我正确的方向或纠正我的 .htaccess 或告诉我如何修改 apache 设置,那就太棒了!

谢谢。

【问题讨论】:

    标签: php linux apache codeigniter mod-rewrite


    【解决方案1】:

    您的网站位于子文件夹中,因此请在第 4 行设置 RewriteBase:

    RewriteBase /Tat
    

    【讨论】:

      【解决方案2】:

      我终于找到答案了!我的服务器配置不正确,我没有启用 mod_rewrite。

      Ubuntu 用户,请在命令行上关闭它以启用它: sudo a2enmod 重写

      然后重新启动 Apache。

      我正在使用以下 .htaccess:

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

      【讨论】:

        猜你喜欢
        • 2012-05-19
        • 1970-01-01
        • 2013-01-08
        • 1970-01-01
        • 2015-09-06
        • 2012-12-06
        • 2011-10-09
        • 2016-07-13
        • 1970-01-01
        相关资源
        最近更新 更多