很难重写codeigniter uri

时间:2014-07-10 00:44:59

标签: php apache .htaccess codeigniter mod-rewrite

我正在网上浏览一些codeigniter教程,但我不得不重写uri's。

这是我的.htaccess代码。

RewriteEngine On
RewriteBase jrdash

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

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

RewriteCond %{REQUEST_FILENAME} !-F
RewriteCond %{REQUEST_FILENAME} !-D
RewriteRule ^(.*)$ index.php?/$1 [L]

我还对配置文件进行了此更改。

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';

.htaccess文件位于根项目文件夹中,项目目录是我的xampp htdocs目录中的jrdash。当我尝试仅通过输入localhost / jrdash来加载页面时出现错误,我之前获得了默认的Codeigniter屏幕,但之后我做了这些更改,现在我收到了错误。

2 个答案:

答案 0 :(得分:0)

我建议您删除第一行和最后三行之间的所有内容并删除该问号。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

答案 1 :(得分:0)

我没有阅读你的整个问题,因为我很确定你犯了一个非常经典的错误:你忘了添加 QSA 指令!

RewriteEngine On
RewriteBase jrdash

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

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

RewriteCond %{REQUEST_FILENAME} !-F
RewriteCond %{REQUEST_FILENAME} !-D
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]