2012-03-03 126 views
0

在删除index.php时出现问题?从网址:CodeIgniter Mod_Rewrite问题

http://localhost/index.php?/reset_password 

随着htaccess文件:

# Customized error messages. 
ErrorDocument 404 /index.php 
# Set the default handler. 
DirectoryIndex index.php 
# Various rewrite rules. 
<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
</IfModule> 

CI设置:

$config['uri_protocol'] = 'AUTO'; 

我看着这里有类似问题的其他线程,但没有自己的htaccess档案工作。我错过了一个设置?

+0

如果您可以通过其他不适合您的'.htaccess'设置链接到帖子,那将非常有帮助。 – 2012-03-03 23:20:46

+0

第一个5 http://stackoverflow.com/search?q=CodeIgniter+Mod_Rewrite+issues – user781439 2012-03-03 23:23:38

回答

5

我从未见过.htaccess之前设置,虽然它可能工作。我用这个每一个CI项目,我已经做了,不妨一试:

<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|themes|uploads) 

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

</IfModule> 

添加不config.php忘记:

/* 
|-------------------------------------------------------------------------- 
| 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'] = ''; 

请记住:这会不会“删除“index.php会自动从您的URL中导出,但如果请求不存在,请将其路由到它。如果您在其中有index.php的硬编码链接,则必须更改它们,否则您需要额外配置.htaccess。如果您使用的是base_url(),site_url()anchor()等CI网址功能,如果您在上面的配置中将它设为空白,它们将不会使用index.php

+0

有趣的是,我在$ config ['index_page'] ='index.php';所以删除后,我的网址现在是:http:// localhost /?/ reset_password。可能还有其他一些设置? – user781439 2012-03-03 23:23:01

+1

你是如何到达该URL的?你没有'$ config ['enable_query_strings']'你呢?如果是这样,你需要关闭它(不要担心这不是你的想法,这是没用的)。用当前URL加载正确的页面,还是忽略'?'后的所有内容? – 2012-03-03 23:24:13

+0

立即工作。非常感谢。我需要确保改变的query_strings不会破坏我的网站,所以我会看看是什么。再次,谢谢!这么多事情要考虑。 – user781439 2012-03-03 23:28:22

0

此代码的工作对我来说:

如果我的网站的名字是codeIgniter_ci_intro

我使用的代码在.htaccess

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /codeIgniter_ci_intro//index.php/$1 [L] 

,我在配置改变。 php

$config['index_page'] = '';