【问题标题】:Remove index.php in code igniter for subfolder删除子文件夹的代码点火器中的 index.php
【发布时间】:2017-05-21 15:33:34
【问题描述】:

我有一些问题。在开发中,我使用的是 php 7,我的网站运行良好。但是在生产中使用 php 5.4 并且我在删除 index.php 时遇到了问题。我的网站托管在子文件夹中,就像myhost/mywebsitefolder

问题出在使用 url 函数时。例如,当我访问“仪表板”页面时,它将重定向到“登录”页面,并且 URL 类似于 myhost/mywebsitefolder/login,它返回 404 页面未找到。当我在登录前添加 index.php (myhost/mywebsitefolder/index.php/login) 时效果很好,但我必须通过添加 index.php 来替换我的所有 url。有没有什么解决办法。我的.htaccess就是这样的。

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

【问题讨论】:

  • 尝试在RewriteRule ^(.*)$ index.php?/$1 [L,QSA]行中添加问号。

标签: php .htaccess codeigniter codeigniter-3


【解决方案1】:

尝试在点前加上斜线,例如:

DirectoryIndex index.php

<IfModule mod_rewrite.c>

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

</IfModule>

<IfModule !mod_rewrite.c>
  ErrorDocument 404 index.php
</IfModule> 

并在application/config/config.php中清除索引页配置值:

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

// New
$config['index_page'] = "";

有时需要开启重写模块,运行“apache2 enable module rewrite”:

sudo a2enmod rewrite

您需要重新启动网络服务器以应用更改:

sudo service apache2 restart

希望它有效!

如果没有,还有其他线程有同样的问题,你可以看看: - Remove index.php from codeigniter in subfolder - Remove index.php from Codeigniter URL in subfolder with Wordpress in root - Using htaccess to remove codeigniter index.php in a subdirectory

【讨论】:

  • 谢谢,我认为问题出在我的 apache 模块中
猜你喜欢
  • 2014-01-15
  • 2013-02-27
  • 1970-01-01
  • 2021-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-19
  • 1970-01-01
相关资源
最近更新 更多