【问题标题】:Codeigniter URLnot found未找到 Codeigniter URL
【发布时间】:2015-08-29 00:21:24
【问题描述】:

我在PHP 中使用Codeigniter 框架。我的网站在 apache 服务器上。路径:/var/www/example.com/public_html

.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

但我在访问此页面时仍然收到此错误:www.example.com/test/wallet:

在此服务器上找不到请求的 URL /test/wallet。

屏幕截图

当我使用www.example.com/index.php/test/wallet 时,它就可以工作了...

【问题讨论】:

  • 检查你的控制器文件和方法。你能分享我们控制器代码吗?你使用 CodeIgniter v3 吗?
  • 您是否将config.php 中的$config['index_page'] = 'index.php'; 更改为$config['index_page'] = '';?看起来您的 .htaccess 正在尝试从 URL 中删除 index.php。
  • example.com/index.php/test/wallet URL 有效吗?
  • 开始于:有什么用吗? :)
  • @Bora:是的。该网址有效

标签: php .htaccess codeigniter


【解决方案1】:

这是我的 .htaccess,它可以在运行 Centos + Apache 和 Ubuntu +apache 的 wamp 和 live linux 服务器上运行

RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
RewriteRule ^(.*)$ /path-to-code-igniter-directory/index.php/$1 [L]

# Added a rewrite to respond with a 200 SUCCESS on every OPTIONS request
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]

我还在这里制作了一个关于如何做到这一点的视频

https://www.youtube.com/watch?v=v-4VkR54vLU

(跳到28:50看.htaccess。我也把它放在视频下面的描述里)

希望对你有帮助

【讨论】:

    【解决方案2】:

    问题在于您的 URL 重写。

    将此放在应用程序文件夹之外

    文件名 = .htacess

    在侧面

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

    【讨论】:

    • 没有。仍然无法正常工作。你能检查一下编辑过的问题吗?
    • 如果我的回答有帮助,请接受或投票。谢谢
    【解决方案3】:

    我认为您的所有.htaccess 设置都是正确的。我使用了@Nassim 的解决方案。

    最初,问题在于apache2.conf 文件中的配置。我只是在/var/www 中设置了 AllowOverride All 并通过此命令在服务器上激活了重写:

    sudo a2enmod rewrite
    

    然后我重启了我的服务器:sudo service apache2 restart

    感谢every1的支持。

    【讨论】:

      猜你喜欢
      • 2013-03-27
      • 2015-05-19
      • 1970-01-01
      • 1970-01-01
      • 2021-09-06
      • 2016-10-29
      • 1970-01-01
      • 2015-01-25
      相关资源
      最近更新 更多