dsnhalq37505 2011-09-15 17:40
浏览 44
已采纳

表单在CodeIgniter中被破坏

I am trying to rewrite my urls to go from /controller/method to index.php?/controller/method, and that is mostly working, except that forms won't submit correctly. I have some routing set up, but the forms are also breaking on non re-routed urls. Here's a little context.

I have moved my index.php out into a separate web folder that is the web root, so there is no chance of exposing application files. I'm not sure whether this would potentially cause this problem, but it's something slightly unusual about my installation. My directory structure looks like:

+ codeigniter/
  + application/
    - models, views, etc
  + system/
  + web/
    - .htaccess
    - index.php
    - css, javascript, images, etc

My .htaccess is pretty simple:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

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

It seems to work fine on XAMPP for Windows, but it is broken on a basic Ubuntu LAMP stack. When I submit a form, nothing happens. The page that the form directs to loads, but as if the form hadn't been submitted.

Sorry, one more important piece of information: If I leave the index.php in there, so the urls look like /index.php/contacts/edit/1, it works.

Let me know if I can provide any more information. Thanks!

  • 写回答

1条回答 默认 最新

  • douzhi6160 2011-09-15 18:35
    关注

    Turns out a part of the .htaccess that I didn't include was causing the error to be difficult to find.

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

    I had assumed that this would show a CodeIgniter error page if it reached that block, but it turns out (I assume) that CodeIgniter was valiantly trying to salvage the situation by looking at the path in $_SERVER, from which it was able to get the page it was supposed to display. However, since the path didn't exist, none of the $_POST data made it through. In the error log I was seeing this line:

    [error] File does not exist: /path/to/web/contacts/edit/1
    

    Enabling mod_rewrite solved the problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误