2011-03-22 187 views
0

我使用codeigniter,当我设置网站时,我在我的.htaccess文件中添加了必要的代码,以从我的url删除index.php(默认)。我刚刚从我网站的备份文件中取代了我的public_html文件夹。由于我这样做,我不能得到主页上的任何链接工作,除非在域名和其他网址之间插入index.php,如http://www.obsia.com/index.php/contact/而不是http://www.obsia.com/contact/,它的工作原理。因此,在应用程序文件夹中的我的配置文件,我改变无法从我的URL在Codeigniter中删除index.php

$config['index_page'] = ""; 

$config['index_page'] = "index.php"; 

和所有的链接似乎现在的工作。但是如何从URL中删除index.php。

这里是我的.htaccess代码如下所示:

RewriteEngine on 
RewriteBase/
RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt|css) 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

任何人都可以点我在正确的方向。它将非常感激。

问候, 摹

回答

3

哟想做的事可以做到这样什么:

RewriteEngine on 
RewriteBase/
# Static content. Rewrite to - (don't change) and mark as last rule. 
RewriteRule !^(index\.php|public|user_guide|robots\.txt|css) - [L] 

# Do the rewrite. 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

然而,这样做的稍微好一点的方法是这样的:

RewriteEngine on 
RewriteBase/
# Only do the rewrite under the condition that the requested URL isn't a (real) file. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ /index.php?/$1 [L] 
+0

我都尝试,它仍然给了我404错误,如果我从URL中删除index.php。我可以删除整个.htaccess文件,但似乎没有什么区别。在我看来,它根本没有考虑.htaccess文件。不知道为什么,什么是压倒一切。 – strangeloops 2011-03-23 08:39:52

+0

试试 RewriteRule ^。* $ - [F,L]这是一个简单的测试,应该在** everything **上显示403禁止。如果这不起作用,也许你没有在Apache配置中启用mod_rewrite。请参阅:http://stackoverflow.com/questions/5390139/htaccess-not-working/5390747#5390747 – nitro2k01 2011-03-23 11:20:34

+0

我没有尝试上述测试,它仍然与404时间每次我点击一个链接(当index.php通过主页从URL中删除)。这是工作之前我昨天恢复网站文件的备份,当我已经备份工作。我确实可以访问httpd.conf文件来启用mod_rewrite。有没有其他办法可以做到这一点? – strangeloops 2011-03-23 15:06:08

2

有是如此之多的HT访问文件...在我的情况下,我正在编辑错误的文件...你应该编辑项目内的文件..例如我工作的代码点火器和项目名称是吨est,所以里面的测试文件夹我有一个htaccess文件,并在我的应用程序文件夹,即测试/应用程序有另一个htaccess文件..我编辑应用程序文件夹内的访问文件,但我不得不编辑测试文件夹中的文件不测试/application/.htaccess ....希望和1个查找这个有用的..因为我花了半天摸不着头脑:(

干杯 KSP