MY CodeIgnitor设置在任何URL上返回404,期望基本网址http://x.example.com/test/)。当我尝试访问http://x.example.com/test/foobar/177等网址时,我会收到以下404:
未找到
在此服务器上找不到请求的网址/index.php/foobar/177。
当我检查我的Web服务器日志(这是Webfaction)时,它只是说:
[Mon Mar 19 12:23:45 2012] [错误] [客户端12.34.56.78]文件没有 存在:/var/www/html/no_app_on_root.htmlindex.php
文件路径与index.php连接的方式是奇数,不是吗?
这是我的.htaccess:
Options +FollowSymLinks
# Set which file that's fetched if only directory is specified
DirectoryIndex index.php index.html index.htm
# don't list category structures
Options -Indexes
# don't display .htaccess files
<Files .htaccess>
order allow,deny
deny from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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]
#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
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
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>
我的routes.php:
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['foobar/177'] = "foobar/foobar_177";
$route['foobar/:num/add'] = "foobar/add";
$route['foobar/:num/review'] = "foobar/review";
$route['foobar/:num'] = "foobar";
我的config.php(是的,该网站位于子域的目录中):
$config['base_url'] = 'http://x.example.com/test/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
答案 0 :(得分:0)
您的重写规则,用于隐藏url中的index.php
RewriteRule ^(.*)$ /index.php/$1 [L]
将所有请求发送到/index.php/$1
并且没有那些处理程序,您需要明确告诉Apache您不希望某些URL被重定向到index.php
答案 1 :(得分:0)
默认情况下,index.php文件将包含在您的网址中:
mywebsite.com/index.php/stories
您可以使用带有一些简单规则的.htaccess文件轻松删除此文件。下面是这样一个文件的示例,使用“否定”方法,除了指定的项目之外,所有内容都被重定向:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
答案 2 :(得分:0)
在文件中:config.php
编辑此行:
$config['uri_protocol'] = 'AUTO';
为:
$config['uri_protocol'] = 'QUERY_STRING';
您的.htaccess文件应如下所示:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]