我在 CodeIgniter 中做了一个项目。它在我的本地主机上运行良好,但在远程服务器上出现“500 内部服务器错误”。这是我的 .htaccess
文件内容:
RewriteEngine On
RewriteBase /ezgov
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
最佳答案
在windows中打开一般位于Apache安装目录下的httpd.conf
/apache/conf/httpd.conf
和
/etc/httpd/httpd.conf
在基于 Unix 的系统中。 httpd.conf 是一个 Apache 配置文件,其中存储了有关服务器的各种信息。
搜索模块 mod_rewrite.so
或(mod_rewrite.c
在极少数情况下)。开发 mod_rewrite 模块是为了即时重写请求的 URL。大多数情况下,您会发现处于注释状态。
#LoadModule rewrite_module modules/mod_rewrite.*
这里的#
字符代表被注释或禁用。
LoadModule rewrite_module modules/mod_rewrite.*
删除 #
并在 Windows 中使用命令 apache -k restart
或在 unix 系统中使用 service httpd restart
重新启动 Apache Http Server。您还可以使用 XAMPP/Wamp UI 在 Windows 系统中重新启动 Apache。
接下来在您的 CodeIgniter 项目所在的根目录中创建 .htaccess
文件并粘贴以下代码
# index file can be index.php, home.php, default.php etc.
DirectoryIndex index.php
# Rewrite engine
RewriteEngine On
# condition with escaping special chars
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
下一步找到 CodeIgniter 配置文件,一般位于它的配置目录中。
./application/config/config.php
打开文件并使 $config['index_page']
值为空。看起来像这样
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';
故事到此结束。一切都应该工作正常。您可以在 Apache Module mod_rewrite 找到有关 httpd.config 的更多信息。 .希望这对你有帮助。谢谢!!
关于php - CodeIgniter PHP Apache 500 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6674689/