2013-10-05 16 views
0

使用codeigniter时,我遇到了一些困难。这是关于URL中的index.php文件。在CodeIgniter的URL中禁用index.php

CodeIgniter服务于所有使用index.php的页面。所以,我们的网址应该像下面:

http://www.example.com/codeigniter/index.php/something 

我想通过编辑config.php文件,并创建一个.htaccess文件删除从URL中index.php。从

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

改变配置来

$config['index_page'] = ''; 

之后我能够没有的index.php就这样跑我的项目:

http://www.example.com/codeigniter/something 

所以,现在,该链接工作 - 但它也适用于index.php片段。我也可以看到地址为http://www.example.com/codeigniter/index.php/something的组件。

我的.htaccess文件是:

RewriteEngine on 
RewriteCond $1 !^(index\.php|resources|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

现在,我想让我的网站只提供没有链接中index.php。我不希望这个网站与链接中的index.php文件一起运行。我想要http://www.example.com/codeigniter/something完美运行,并且http://www.example.com/codeigniter/index.php/something不能运行。我怎样才能做到这一点?

+0

可以粘贴您的虚拟主机的配置? – Mauro

+0

对不起,什么是vhost配置?我正在使用xampp在localhost中托管我的项目 – user2849692

回答

1

你可以尝试添加在你.htaccess文件中的以下

RewriteCond %{THE_REQUEST} codeigniter\/index\.php 
RewriteRule codeigniter\/index\.php -[F] 

基本上,这个规则告诉如果请求包含笨/ index.php文件

0

添加一个上面这条规则返回禁止回应您已经有:

RewriteCond %{THE_REQUEST} \ /codeigniter/index\.php([^\?\ ]*) 
RewriteRule^/codeignighter/%1 [L,R=301] 

而且它会将其中有index.php的请求重定向到没有它的URL。

1

试试这个

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$0 [PT,L] 

将代码放在你的根文件夹htaccess.Please让我知道,如果你面对任何问题

0

您应该添加?之后index.php,所以它在所有主机。这是我的htaccess

RewriteEngine On 
#RewriteBase/ maybe you don't need it, depends on the hosting 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(index\.php|robots\.txt|humans\.txt|license\.txt|sitemap\.xml|assets) 
RewriteRule ^(.*)$ index.php?/$1 [L] 

相关问题