【问题标题】:Removing index.php in CodeIgniter resulting 5xx server error删除 CodeIgniter 中的 index.php 导致 5xx 服务器错误
【发布时间】:2013-07-31 20:15:38
【问题描述】:

假设我有以下网址

subdomain.example.com/myfolder

其中“myfolder”是我的 CI 安装的根文件夹(应用程序文件夹所在的位置)。

我有以下 .htaccess(感谢 Fabdrol 和 ElliotHaughin):

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

当我尝试访问我的网站时,例如:

subdomain.example.com/myfolder/controller/etc...

它总是返回 5xx 内部服务器错误。但是,如果我添加

subdomain.example.com/myfolder/index.php/controller/etc...

完美运行。我很确定我的 .htaccess 有问题我只是看不出问题出在哪里。

谁能帮我修复我的htaccess?谢谢

* 仅供参考 * 我还尝试在我的 config.php 上更改以下行

$config['index_page'] = ''; // Originally set to index.php
$config['uri_protocol'] = 'REQUEST_URI' // Originally set to AUTO

当我改变:

RewriteEngine On
RewriteBase /myfolder

但它不会返回 500,它根本不显示任何内容。

只是提供一些有关myfolder结构的信息

public_html
---|
   |
   |--mysubdomain_folder
   |     |
   |-----|--myfolder (my website where index.php, .htaccess and application folder are).

【问题讨论】:

  • @MadanSapkota 我试过了,但没有运气。 .htaccess 配置在我的其他站点(非子域站点)上完美运行。
  • 您的 httaccess 文件在 Web 根目录或 CI 根目录中的什么位置?
  • ci root,我把它和 index.php 文件,控制器文件夹和其他东西放在一起。

标签: php .htaccess codeigniter


【解决方案1】:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]

【讨论】:

  • 对不起,伙计,但它不起作用。我什至无法访问 subdomain.example.com/mywebsite(这会引发 5xx 错误)。
【解决方案2】:

我想我可能已经使用这个配置解决了它:

我的 .htaccess 文件:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myfolder

#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,QSA]
</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.php 文件:

$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

事实证明,由于我的应用程序(我的 ci_root)不在我的根目录(public_html)中,我需要将 RewriteBase 从“/”修改为“/path_to_your_application”

事实证明,如果您正在创建一个名为“subdomain”的子域,它将在您的 public_html 中创建一个名为“subdomain”的文件夹,您应该将其视为子域的 root。因此我将我的 RewriteBase 设置为“/myfolder”而不是“/my_subdomain_folder/myfolder”。

我希望这个解决方案可以帮助其他人。

感谢大家的帮助和提示。

【讨论】:

    【解决方案3】:

    只需添加一个 ?在 index.php 之后

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|robots\.txt|humans\.txt|license\.txt|sitemap\.xml|assets)
    RewriteRule ^(.*)$ index.php?/$1 [L]
    

    我还建议让查看文件而不是目录:

    Options -Indexes
    

    【讨论】:

      猜你喜欢
      • 2016-04-15
      • 1970-01-01
      • 1970-01-01
      • 2018-01-27
      • 2014-11-25
      • 2013-09-04
      • 1970-01-01
      • 2014-01-07
      • 2015-03-11
      相关资源
      最近更新 更多