我已经把头发拉了三天,我用Google搜索了所有东西,一直在代码点火器论坛上,从上到下检查堆栈溢出。
我想要做的就是从网址中删除index.php。我找到的最接近我的问题的帖子没有回答: Post
如果我转到localhost/CodeIgniter
,我的主页就会显示出来。如果我点击我的链接,我会收到页面不存在的错误。
404 Page Not Found
The page you requested was not found.
根据我读过的所有内容,这是我当前的配置。
MAC OSX 10.8.3 MAMP CodeIgniter 2.1.3
我的根目录是www / CodeIgniter / 这是CodeIgniter Root中的.htaccess文件
#Deny from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /CodeIgniter/
#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>
以下是CodeIgniter的配置设置:我尝试了uri_protocol的每个设置都没有成功
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
我确认我启用了mod_rewrite,并且在httpd.conf中将AllowOverride设置为All。
**** UPDATE 所以我删除了MAMP和codeigniter并从头开始。现在使用下面的.htaccess文件,当我转到localhost时,不会显示codeigniter文件夹。如果我尝试浏览到该文件夹,我会收到以下错误。
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, you@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
当我查看错误日志时,我有以下错误。
[Mon Apr 22 21:42:51 2013] [alert] [client ::1] /Users/me/Dropbox/www/codeigniter/.htaccess: <IfModule takes one argument, Container for directives based on existance of specified modules
我确认我的phpinfo();
启用了mod_rewrite如果我删除.htaccess文件,我可以浏览到该文件夹并获取主页,但当然链接不起作用。任何建议都将不胜感激。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /codeigniter/
#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>
答案 0 :(得分:0)
仅出于测试目的备份您的htaccess文件,然后将其完全清除并粘贴到:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
看看您是否可以毫无错误地浏览网站。
答案 1 :(得分:0)
嘿,为什么不做一件事...下载此代码点火器安装https://github.com/amitavroy/cleanplate,然后检查这是否会没有错误。你mod_rewrite应该是在场外
答案 2 :(得分:0)
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
内部配置文件:
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'REQUEST_URI'; //or 'QUERY_STRING'
答案 3 :(得分:0)
迟到总比没有好,但我不得不修改我的httpd.conf文件,经过三次重启后它就开始工作了。也许这可以帮助别人
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
答案 4 :(得分:0)
只需在.htaccess文件中粘贴以下内容即可
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /CodeIgniter/index.php/$1 [L]
设置 $ config ['index_page'] =''; //config.php $ config ['uri_protocol'] ='REQUEST_URI'; // config.php