[英].htaccess throws a 500 error
I am using CodeIgniter and need to get rid of the "index.php" in the URL. 我正在使用CodeIgniter,需要删除URL中的“ index.php”。 I copied the .htaccess file from codeigniter tutorial, emptied the $config['index_page'] = ''; 我从codeigniter教程中复制了.htaccess文件,清空了$ config ['index_page'] =''; and put the .htaccess in the root directory. 并将.htaccess放在根目录中。 Without the .htaccess file it works fine, but ugly: www.example.com/index.php/site/home For some reason it's not working and just throws a 500's error. 没有.htaccess文件,它可以正常工作,但是很难看:www.example.com/index.php/site/home出于某种原因,它无法正常工作,只会抛出500的错误。
Where is the bug and how can I resolve it? 错误在哪里,我该如何解决?
Thank you in advance 先感谢您
My .htaccess file: 我的.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folders by users.
#Additionly this will allow you to create a System.php controller,
#previously this would not have not 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>
My site controller: 我的站点控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller {
public function index(){
$this->home();
}
public function home(){
echo "default function started.<br/>";
$this->hello();
$data['title'] = 'Home!';
$data['name'] = 'Ilia';
$data['fname'] = 'Lev';
$data['operation'] = 'minus';
$data['val1'] = 5;
$data['val2'] = 7;
echo $data['operation']."<br/>";
$data['result'] = $this->math($data);
$this->viewLoad("home_view", $data);
echo "<br/>";
}
public function hello(){
echo "hello function started.<br/>";
}
public function math($data){
$operation = $data['operation'];
$val1 = $data['val1'];
$val2 = $data['val2'];
$this->load->model("math");
return $this->math->calculate($operation, $val1, $val2)."<br/>";
}
public function viewLoad($whatToView, $data){
try{
$this->load->view($whatToView, $data);
}catch(Exception $e){
echo "There is no such view";
}
}
public function about(){
$data['title'] = "About!";
$this->viewLoad("about_view",$data);
}
}
If this is really part of the .htaccess
file, it would cause your problem: 如果这确实是.htaccess
文件的一部分,则可能会引起您的问题:
RewriteRule ^{.*)$ /index.php?/$1 [L]
^^^ typo?
Should be: 应该:
RewriteRule ^(.*)$ /index.php?/$1 [L]
I too had the same problem but my code was correct and i was using wamp server, then I found rewrite module is not enabled 我也有同样的问题,但是我的代码是正确的,并且我正在使用wamp服务器,然后我发现未启用重写模块
so went to apache/conf/httpd.conf and uncommented line 所以去了apache / conf / httpd.conf和未注释的行
LoadModule rewrite_module modules/mod_rewrite.so LoadModule rewrite_module模块/mod_rewrite.so
Now its working fine. 现在工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.