CodeIgniter从url中删除index.php

时间:2013-11-10 21:13:10

标签: php apache .htaccess codeigniter configuration

我在从我的CI应用网址中删除index.php时遇到了一些问题。遵循官方文件here,但显然还有一些遗漏。 我设置了一个CI应用程序并将其放在我的服务器上的/ var / www / test上,其中test是指向/ home / user / websites / test的符号链接。 如果我http://myIp/test/index.php/welcome,一切正常,但如果我做http://myIp/test/welcome则工作正常。 我在我的测试文件夹中包含了一个.htaccess,其中包含以下内容:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

并且还使用RewriteBase属性而没有成功。 我做错了什么或错过了什么?

5 个答案:

答案 0 :(得分:1)

将以下内容放入.htaccess

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

<Files "index.php">
AcceptPathInfo On
</Files>

将此文件放在index.php附近的应用程序和系统文件夹中,并靠近它们 别忘了写$ config ['index_page'] ='';而不是$ config ['index_page'] ='index.php';

答案 1 :(得分:0)

打开application/config/config.php,然后更改

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

$config['index_page'] = '';

答案 2 :(得分:0)

试试这个:

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

答案 3 :(得分:0)

您的重写规则不正确(或最好是错误的)。它应该如下

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

[L]中的RewriteRule标志表示不应处理其他规则并且应立即应用该规则。有关详细信息,请参阅apache documentation about the L flag。在您的情况下,这很重要,因为您使用符号链接和.htaccess文件而不是直接将规则应用于您的vhost文件,强烈建议考虑到这种情况以及.htaccess很慢的情况

答案 4 :(得分:0)

如果我的问题是正确的,那么你想让你的链接正常工作。从URL.Follow中删除'index.php'以下步骤&amp;如果能解决您的问题,请告诉我。

1)从config.php中删除'index.php',它位于config目录中,使其看起来像$config['index_page'] = '';

2)将此添加到.htaccess文件

DirectoryIndex index.php
RewriteEngine on

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

如果您有任何疑问或问题,请告诉我。希望它有所帮助。

最诚挚的问候,Zeeshan。