CodeIgniter 中的表单被破坏
我正在尝试重写我的网址,从 /controller/method 到 index.php?/controller/method,这大部分都有效,只是表单无法正确提交。我设置了一些路由,但表单也因非重新路由的网址而中断。这是一些背景信息。
我已将 index.php 移至一个单独的 Web 文件夹(即 Web 根目录)中,因此不会暴露应用程序文件。我不确定这是否会导致此问题,但我的安装有点不寻常。我的目录结构如下所示:
+ codeigniter/
+ application/
- models, views, etc
+ system/
+ web/
- .htaccess
- index.php
- css, javascript, images, etc
我的 .htaccess 非常简单:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
它似乎在 Windows 的 XAMPP 上运行良好,但在基本的 Ubuntu LAMP 堆栈上却损坏了。当我提交表单时,什么也没有发生。表单定向到的页面会加载,但就好像表单尚未提交一样。
抱歉,还有一条更重要的信息:如果我将index.php留在那里,那么网址看起来像/index.php/contacts/edit/1
,它就可以工作。
如果我可以提供更多信息,请告诉我。谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我没有包含的 .htaccess 的一部分导致了错误很难找到。
我原以为如果到达该块,就会显示 CodeIgniter 错误页面,但事实证明(我假设)CodeIgniter 正在勇敢地尝试通过查看 $_SERVER 中的路径来挽救这种情况,它能够从中获取应该显示的页面。但是,由于该路径不存在,因此 $_POST 数据均无法通过。在错误日志中我看到这一行:
启用 mod_rewrite 解决了问题。
Turns out a part of the .htaccess that I didn't include was causing the error to be difficult to find.
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:Enabling mod_rewrite solved the problem.