1 php .htaccess mod-rewrite codeigniter-url codeigniter-2
我有一个我在codeiginiter 2.0.1(我自己的个人网站)上建立的网站.我使用WAMP在本地构建了这个应用程序,它可以100%正常工作(本地).我将其上传到我的实时服务器,并且一直收到"找不到404页面"错误.这个错误来自codeigniter通过我的Home-> Error方法,而不是服务器,因此代码点火器肯定是有效的.
这是我的路线配置.如果我将404_override更改为"Home".它会加载我的家庭控制器,但是当我转到任何页面时,我找不到404页面.
$route['default_controller'] = 'Home';
$route['404_override'] = 'Home/Error';
Run Code Online (Sandbox Code Playgroud)
我怀疑这可能与我的.htaccess和Codeigniter配置有关.
// Codeigniter Config.php - Note: My Hosting is with Godaddy. [CGI/FastCGI]
$config['index_page'] = 'index.php?';
// Tried Auto and All others, REQUEST_URI works fastest for me.
$config['uri_protocol'] = 'REQUEST_URI';
Run Code Online (Sandbox Code Playgroud)
我的.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]
Run Code Online (Sandbox Code Playgroud)
我通过SO和Google尝试了很多这样的链接来解决这个问题,我重复尝试的那些链接在下面.
- CodeIgniter 404找不到页面,但为什么?
- 现有的控制器上的笨404
- http://codeigniter.com/forums/viewthread/60469/#297477
- http://codeigniter.com/wiki/Godaddy_Installaton_Tips
-以及很多其他
我敢肯定这已经与htaccess和mod_rewrite,任何想法?
$route['404_override'] = 'Home/Error'为我的任何控制器,它们会按预期显示和工作,但由于某种原因,它总是会抛出404页面.
如果我去:/index.php/home- 我得到错误No input file specified.
第一个控制器名称应为小写,如:
$route['default_controller'] = 'home';
然后你可以将index_page留空:
$config['index_page'] = '';
最后在.htaccess中应该与基本路径目录中的index.php一起,你可能会改变最后一行,如:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /home/index.php?$1 [L]
希望它能解决