【发布时间】:2014-05-10 03:57:28
【问题描述】:
为什么这在我的本地环境中起作用,但在我运行 cpanel 的生产服务器上却出现 404:
$adminDir = get_bloginfo('template_directory');
$adminDir = $adminDir."/lib/admin/";
$preview_file = $adminDir.'functions/live_preview.php';
wp_register_script( 'admin', $adminDir."js/admin.js", false, '1.0' ); //register script
$wp_paths = array( 'template_url' => $adminDir.'functions/live_preview.php');
wp_localize_script( 'admin', 'object_name', $wp_paths );
wp_enqueue_script("admin");
我不确定要提供什么其他信息,我在本地运行 ubuntu 和 apache,我知道我的生产环境正在运行一些带有 apache 的 linux。我有一些 JS 向相关页面发送 ajax 请求:
$.ajax({
url: object_name.template_url,
type: 'POST',
data: { data: data },
success: function(result) {
kjd_reload_styles();
}
});
我在本地环境中没有收到错误,但我的 ajax 响应在生产中导致 404。这是为什么呢?
BUMP - 所以有问题的文件是:
http://sandbox.kylejenningsdesign.com/wp-content/themes/bootstrappedWP/lib/admin/functions/live_preview.php
试图打到 404 失败。但是如果你去它的父目录:
http://sandbox.kylejenningsdesign.com/wp-content/themes/bootstrappedWP/lib/admin/functions
您可以看到文件列表(顺便说一下,所有这些都是 404)。这是怎么回事?
这是我的 .htaccess 文件,它看起来像标准的 wordpress .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
添加错误日志:
我浏览了我的 cpanel 错误日志,这就是我发现的。有两种类型的日志,一种显示最后 300 条日志,还有一种更深入的日志。 基本日志只显示了这一点(事实上,这个错误是今天在我的 ajax cal 操作之后出现的)
[Sat Apr 19 18:30:43 2014] [error] [client 76.100.35.2] SoftException in Application.cpp:629: Directory "/home/kylejenn/public_html/sandbox/wp-content/themes/bootstrappedWP/lib" is writeable by group, referer: http://sandbox.kylejenningsdesign.com/wp-admin/admin.php?page=kjd_header_settings
un Apr 20 15:31:49 2014] [error] [client 173.71.202.111] SoftException in Application.cpp:629: Directory "/home/kylejenn/public_html/sandbox/wp-content/themes/bootstrappedWP/lib" is writeable by group, referer: http://sandbox.kylejenningsdesign.com/wp-admin/admin.php?page=kjd_body_settings
**The in depth error logs show:**
[18-Apr-2014 15:15:36 UTC] WordPress database error MySQL server has gone away for query SELECT option_value FROM wp_options WHERE option_name = '_transient_doing_cron' LIMIT 1 made by _get_cron_lock
[19-Apr-2014 20:04:48 UTC] WordPress database error Unknown column 'z6p9z9mlt_posts.post_type' in 'where clause' for query SELECT z6p9z9mlt_comments.* FROM z6p9z9mlt_comments WHERE comment_post_ID = '206' AND comment_approved = '1' AND z6p9z9mlt_posts.post_type NOT IN('project', 'task_list', 'task', 'milestone', 'message') ORDER BY comment_date_gmt DESC LIMIT 10 made by require('wp-blog-header.php'), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts
【问题讨论】:
-
object_name.template_url返回本地和在线什么? -
在生产中根本找不到文件,我什至无法在浏览器中提取文件。但是我在本地环境中的浏览器中提取文件
-
您可能需要包含您的 .htaccess。可能有一些重写会使您的文件变成 404。
-
将永久链接设置为“默认”,然后尝试。
-
@MichalS,我只是将它们更改为默认值,但它仍然无法正常工作,但这次我的控制台给了我 500 错误。尝试通过浏览器访问这些文件会将我带到首页。也就是说,我的本地环境中的永久链接没有设置为默认值,我在那里没有这个问题。
标签: javascript php ajax wordpress http-status-code-404