【问题标题】:.htaccess file in codeigniter present a 500 error page [closed]codeigniter 中的 .htaccess 文件显示 500 错误页面 [关闭]
【发布时间】:2012-02-06 01:19:08
【问题描述】:

我刚刚完成了我的网站,使用 codeigniter,我将该网站作为插件域上传到了 bluehost 帐户

我不使用 query_strings,这是我的配置文件中的位置:

 $config['enable_query_strings'] = FALSE;

该网站在我的测试服务器上运行良好,但将其上传到我的 bluehost 帐户,我在尝试导航任何页面时遇到一些问题,否则主页

问题是在主机的根目录中存在另一个 codeigniter 网站并具有 .htaccess 文件以使其正常工作,因此在创建指向主域站点内的文件夹的新站点时,我认为存在问题使用我的插件站点的 .htaccess

这是我的插件站点的 .htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /http://www.mydomain.com/

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

【问题讨论】:

  • 一次注释掉一行,哪一行导致 500 错误,重写基础看起来也很可疑,但我 100% 确定
  • 重写基础RewriteBase /http://www.domain.com/????
  • @Bookf of Zeus:是的,我认为它使重定向混乱,可能无法访问或内部循环?
  • RewriteBase /sample-domain.com
  • RewriteBase 可以是 / 但只需将 DirectoryIndex 设置为应用程序索引所在的位置

标签: php .htaccess codeigniter


【解决方案1】:

查看 Apache doc on RewriteBase:

默认设置为:RewriteBasephysical-directory-path

当新 URL 发生替换时,此模块必须将 URL 重新注入服务器处理。为了能够做到这一点,它需要知道相应的 URL 前缀或 URL 基是什么。默认情况下,此前缀是相应的文件路径本身。但是,对于大多数网站来说,URL 与物理文件名路径没有直接关系,因此这种假设通常是错误的!因此,您可以使用 RewriteBase 指令来指定正确的 URL 前缀。

bluehost 如何实现附加域?如果您可以使用控制面板将http://www.mydomain.com/ 指向DOCROOT/addon,那么这个.htaccess 文件在DOCROOT/addon 中,那么在这种情况下它应该是:

RewriteBase /

如果它只是将所有映射域指向 DOCROOT(就像我的那样),那么您需要使用 %{HTTP_HOST} 解码和RewriteConds 并且在相关 Qs 中有很多示例说明如何执行此操作,这需要DOCROOT .htacces 中的额外调度行,例如

RewriteCond %{REQUEST_URI}        !^/addon/                [NC]
RewriteCond %{HTTP_HOST}          =www.mydomain.com        [NC]
RewriteRule  ^(.*)                addon/$1                 [L]

【讨论】:

    【解决方案2】:

    谢谢大家,谢谢 Eli 你解决了,我添加了目录索引,这是最终的 .htaccess 文件:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|images|img|css|js|robots\.txt)
    RewriteCond $1 !^(index\.php|application/views/|robots\.txt|install|favicon\.ico|documents)
    RewriteRule ^(.+)$ index.php?$1 [L]
    RewriteBase /
    DirectoryIndex index.php
    
    
    #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> 
    

    【讨论】:

      猜你喜欢
      • 2014-11-10
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      • 2017-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-12
      相关资源
      最近更新 更多