笨的mod_rewrite给404错误(CodeIgniter mod_rewrite gives

2019-07-17 23:40发布

我写了一个笨应用程序,我想使用mod_rewrite清理我的网址。 我已经安装在的htdocs / CI-介绍的笨应用/

这里是我的.htaccess文件:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/

#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> 

我改变了config.php文件CI中的以下内容:

$config['base_url'] = '';
$config['index_page'] = '';

每当我用我的链接转到页左右我从笨404消息。 在浏览器的URL似乎是“清理”,但(index.php文件被删除)。 这是网址:

的 'http://本地主机:8888 / ci_intro /约'

任何人可以帮助我摆脱404错误,并指导实际使用的有关页面?

操作系统:Mac OS X 10.8.2(最新)
服务器软件:甲基苯丙胺
PHP:5.2.17
浏览器:Chrome和Safari浏览器(在这两种浏览器就会出现此问题)

Answer 1:

查看您的服务器CONFIGRATION之前,请尝试以下代码:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/

#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.*
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> 


Answer 2:

试试这个...

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /Your_folder_Name/index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /Your_folder_Name/index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ Your_folder_Name/index.php?/$1 [L]
</IfModule>


Answer 3:

巧合的是,我使用像你一样的配置,并最终它并没有真正的工作,无论我如何改变它。

于是我放弃了改变它,并试图另一个简单的设置。 尝试了这一点,这对我的作品! :)

<IfModule mod_rewrite.c>

RewriteEngine on

# If the start of the URL doesn't match one of these...
RewriteCond $1 !^(index\.php|robots\.txt|assets|cache|images|uploads)

# Route through index.php
RewriteRule ^(.*)$ index.php/$1 [L]



Answer 4:

RewriteCond %{REQUEST_URI} ^system.*

大概是不会触发,因为与REQUEST_URI /启动。 尝试

RewriteCond %{REQUEST_URI} ^/system

同上,用于

RewriteCond %{REQUEST_URI} ^application.*

与您的系统是否真的要/index.php?/blah胡说? 这将期待后的URL查询字符串?



文章来源: CodeIgniter mod_rewrite gives 404 error