【问题标题】:Unable to remove index.php from Codeigniter URl无法从 Codeigniter URl 中删除 index.php
【发布时间】:2013-08-05 08:07:10
【问题描述】:

我无法从我的项目 URL 中删除 index.php。下面是我尝试过的代码。

以下相同的代码和配置设置适用于我在同一台服务器上托管的另一个项目

在 .htaccess 文件中

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|imgs)
RewriteRule ^(.*)$ index.php/$1 [L]  
RewriteRule ^media/images/([0-9]+)/([A-Za-z0-9-]+).jpg?$ imgs/$1  [T=image/jpeg,L]
<Files "index.php">
AcceptPathInfo On
</Files>

.htaccess 文件与应用程序文件夹平行放置在根文件夹下。

在 config.php 文件中

$config['uri_protocol'] = 'PATH_INFO';
(also tried same for all server global mentioned in config.php)

and

$config['index_page'] = '';

当前项目 url 类似于 http://Hostname/ODP/(这不适用于上述代码)

以前的项目 url 是 http://Hostname/WCP/(这个适用于上述代码)

【问题讨论】:

  • 您是否为每个项目创建了单独的虚拟主机?
  • 抱歉,我不知道 vhost 这个词……听起来像虚拟主机……它如何解决上述问题?
  • 配置中的base_url是什么?
  • ("hostname/ODP/") 设置为base_url
  • 尝试将http://hostname/ODP/ 用作base_url,请尝试阅读此stackoverflow.com/questions/5155333/…

标签: php codeigniter redirect


【解决方案1】:
Use following htaccess code to remove index.php from your codeigniter url
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]

【讨论】:

    猜你喜欢
    • 2013-08-09
    • 2012-12-27
    • 1970-01-01
    • 2023-03-25
    • 2015-05-26
    • 1970-01-01
    • 2012-11-14
    • 2016-05-14
    • 2014-10-28
    相关资源
    最近更新 更多