非常奇怪的 Drupal 7 404 行为

2021-12-29 00:00:00 forms php drupal drupal-7

我在 D7 中有一些我以前从未见过的非常奇怪的行为.我已将一个新站点从我的开发机器迁移到测试机器,因此代码和数据库是相同的.在开发机器(Ubuntu 13.04、Apache、PHP 5.5.3)上,一切正常,但在 Raspbian 上运行 PHP 5.4.4 的 Raspberry Pi 测试盒上,我似乎在提交表单时遇到 404 错误.似乎发生的情况是,当您查看 HTTP 响应时,未处理表单并返回原始页面,但带有 404 状态代码.

这会影响使用 POST 的所有内容,包括登录.我确实通过使用 Firefox 的 Web 开发人员工具将登录表单的action"属性更改为指向/",设法让它登录,但许多其他事情不起作用,管理菜单偶尔会消失.

认为这可能是缓存问题,因此手动截断了所有缓存表,但这没有任何区别.一个不存在的临时文件夹似乎有问题,所以我创建了一个它期望的 777 perms(因为我无法更改设置,因为表单提交不起作用......)但不是这个任何一个.干净的网址工作正常.

以前从未见过这样的事情.任何想法最受赞赏!

解决方案

这似乎是这个问题的答案(摘自问题下方 OPer 的评论):

<块引用>

我忘记启用 mod_rewrite 和 mod_headers!让我感到惊讶的是,没有它们,干净的 URL 也能正常工作.我认为这是因为 .htaccess 将 404s 指向 Drupal,然后 Drupal 将解释请求的 URL 并显示适当的页面,但当然 Apache 发送的是 404 标头.

I am having some very strange behaviour in D7 that I have not seen before. I have migrated a new site from my dev machine to a test machine, so code and DB are identical. On the dev machine (Ubuntu 13.04, Apache, PHP 5.5.3), everything works fine, but on the test box which is a Raspberry Pi running PHP 5.4.4 on Raspbian, I seem to get 404 errors on form submission. What seems to happen is that the form is not processed and the original page is returned but with a 404 status code when you look at the HTTP response.

This is affecting everything that uses POST, including login. I did manage to get it to log in by changing the 'action' attribute of the login form to point to '/' using Firefox's web developer tools, but lots of other things didn't work and the admin menu occasionally disappeared.

Thought it might be a caching issue so manually truncated all the cache tables but that made no difference. There appeared to be an issue with a non-existent temp folder so I created the one it was expecting with 777 perms (as I couldn't change the setting because form submission wouldn't work...) but it wasn't this either. Clean URLs are working fine.

Never seen anything like this before. Any ideas most appreciated!

解决方案

Here is what seems to be the answer to this question (taken from a comment from OPer below the question):

I'd forgotten to enable mod_rewrite and mod_headers! What I was amazed about was that clean URLs were working at all without them. I think this is because .htaccess points 404s to Drupal, which will then interpret the requested URL and show the appropriate page, but of course Apache is sending a 404 header.

相关文章