CodeIgniter 从 url 中删除索引.php


CodeIgniter remove index.php from url

我在从我的 CI 应用程序 URL 中删除索引.php时遇到一些问题。遵循了这里的官方文档,但显然还缺少一些东西。我设置了一个 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]

并且还玩了重写基础属性但没有成功。我做错了什么或错过了什么?

将以下内容放在 .htaccess 中

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

将此文件放在索引附近.php应用程序和系统文件夹之外并靠近它们不要忘记写$config['index_page'] = '';而不是 $config['index_page'] = '索引.php';

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

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

$config['index_page'] = '';

试试这个:

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

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

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

RewriteRule中的[L]标志向 apache 指示不应处理进一步的规则,并且应立即应用该规则。有关此内容的更多信息,请参阅有关 L 标志的 apache 文档。在您的情况下,这很重要,因为您使用的是符号链接和.htaccess文件,而不是将规则直接应用于您的虚拟文件,鉴于这种情况以及 .htaccess 速度很慢的情况,强烈建议这样做。

如果我

的问题是正确的,你想让你的链接工作并从URL中删除"index.php"。请按照以下步骤操作,让我知道是否可以解决您的问题。

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

2) 将其添加到 .htaccess 文件

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

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

最好的问候,泽山。