草庐IT

php - 当浏览器请求一个脚本(由 PHP 动态生成)时,我得到一个 404,但如果我直接去那里,它就可以工作

coder 2024-04-19 原文

我正在用 PHP 生成我的 javascript。如果我包含这样的脚本标签

<script src="http://www.everythingpuntagorda.com/blog?ai1ec_render_js=common_backend&amp;is_backend=true&amp;is_calendar_page&amp;ver=1.11.1-pro" type="text/javascript"></script>

浏览器返回 404

但是如果你去http://www.everythingpuntagorda.com/blog?ai1ec_render_js=common_backend&is_backend=true&is_calendar_page&ver=1.11.1-pro

您会看到 javascript 已按预期创建。这是我们的 .htaccess

DirectoryIndex index.php

#BEGIN HG BLOCK 
#order deny,allow 
#allow from 74.202.255.240/29 
#allow from 216.110.94.176/28 
#allow from 216.110.94.224/27 
#allow from 199.187.122.66 
#allow from 199.187.122.67 
#allow from 78.46.70.238 
#allow from 204.187.12.90 
#allow from 74.86.15.72 
#allow from 180.149.241.242 
#allow from 175.107.133.185 
#allow from 217.27.250.160 
#allow from 174.58.72.114 
#allow from 66.87.109.196 
#deny from all 
#END HG BLOCK

# BEGIN WPSuperCache 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase / 
#If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible 
AddDefaultCharset UTF-8 
RewriteCond %{REQUEST_URI} !^.*[^/]$ 
RewriteCond %{REQUEST_URI} !^.*//.*$ 
RewriteCond %{REQUEST_METHOD} !POST 
RewriteCond %{QUERY_STRING} !.*=.* 
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$ 
RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC] 
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC] 
RewriteCond %{HTTP_USER_AGENT} !^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).* [NC] 
RewriteCond %{HTTP_user_agent} !^(w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-).* [NC] 
RewriteCond %{HTTP:Accept-Encoding} gzip 
RewriteCond %{HTTPS} on 
RewriteCond %{DOCUMENT_ROOT}/blog/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz -f 
RewriteRule ^(.*) "/blog/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz" [L]

</IfModule>

# END WPSuperCache

# 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

这是生成javascript的函数

/**
 * Render the javascript for the appropriate page
 * 
 */
public function render_js() {
    header( 'Content-Type: application/javascript; charset=utf-8' );
    // Aggressive caching to save future requests from the same client.
    $etag = '"' . md5( __FILE__ . $_GET[self::LOAD_JS_PARAMETER] ) . '"';
    header( 'ETag: ' . $etag );
    $max_age = 31536000;// One Year
    header(
        'Expires: ' .
        gmdate(
            'D, d M Y H:i:s',
            Ai1ec_Time_Utility::current_time() + $max_age
        ) .
        ' GMT'
    );
    header( 'Cache-Control: public, max-age=' . $max_age );
    if (
        empty( $_SERVER['HTTP_IF_NONE_MATCH'] ) ||
        $etag !== stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] )
    ) {
        // compress data if possible
        if ( true === extension_loaded( 'zlib' ) ) {
            ob_start( 'ob_gzhandler' );
            header( 'Content-Encoding: gzip' );
        } else {
            ob_start();
        }

        $js_path = AI1EC_ADMIN_THEME_JS_PATH . DIRECTORY_SEPARATOR;
        $common_js = '';
        $page_to_load = $_GET[self::LOAD_JS_PARAMETER];

        if ( $_GET[self::IS_BACKEND_PARAMETER] === self::TRUE_PARAM ) {
            $common_js = file_get_contents( $js_path . 'pages/common_backend.js' );
        } else if( $page_to_load === self::EVENT_PAGE_JS ||
            $page_to_load === self::CALENDAR_PAGE_JS || 
            $page_to_load === self::LOAD_ONLY_FRONTEND_SCRIPTS ) {
            if ( $page_to_load === self::LOAD_ONLY_FRONTEND_SCRIPTS &&
                true === self::$frontend_scripts_loaded ) {
                return;
            }
            if ( false === self::$frontend_scripts_loaded ) {
                $common_js = file_get_contents( $js_path . 'pages/common_frontend.js' );
                self::$frontend_scripts_loaded = true;
            }

        }
        // create the config object for require js
        $require_config = $this->create_require_js_config_object();
        // load require
        $require = file_get_contents( $js_path . 'require.js' );

        // get jquery
        $jquery = $this->get_jquery_version_based_on_browser( 
            $_SERVER['HTTP_USER_AGENT']
        );
        // load the script for the page

        $page_js = '';
        if ( $page_to_load !== self::LOAD_ONLY_BACKEND_SCRIPTS &&
             $page_to_load !== self::LOAD_ONLY_FRONTEND_SCRIPTS
        ) {
            $page_js = file_get_contents( $js_path . 'pages/' . $page_to_load );
        }


        $translation = $this->get_frontend_translation_data();
        $permalink = get_permalink( $this->settings->calendar_page_id );

        $translation['calendar_url'] = $permalink;

        $tranlsation_module = $this->create_require_js_module( 
            self::FRONTEND_CONFIG_MODULE, 
            $translation 
        );
        $config = $this->create_require_js_module(
            'ai1ec_config',
            $this->get_translation_data()
        );
        echo $require . $require_config . $tranlsation_module . 
                $config . $jquery . $page_js . $common_js;
        ob_end_flush();
    } else {
        // Not modified!
        status_header( 304 );
    }
    // We're done!
    ai1ec_stop( 0 );
}

我让我们的系统管理员查看了这个但没有效果

最佳答案

尝试在返回 javascript 的 php 中添加:

    header('HTTP/1.1 200 OK');
    header('Content-Type: application/javascript');
    echo "your javascript goes here";

关于php - 当浏览器请求一个脚本(由 PHP 动态生成)时,我得到一个 404,但如果我直接去那里,它就可以工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17449249/

有关php - 当浏览器请求一个脚本(由 PHP 动态生成)时,我得到一个 404,但如果我直接去那里,它就可以工作的更多相关文章

  1. ruby - 使用 RubyZip 生成 ZIP 文件时设置压缩级别 - 2

    我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看ruby​​zip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d

  2. ruby - 使用 Vim Rails,您可以创建一个新的迁移文件并一次性打开它吗? - 2

    使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta

  3. ruby-on-rails - Rails - 一个 View 中的多个模型 - 2

    我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何

  4. ruby-on-rails - 渲染另一个 Controller 的 View - 2

    我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>

  5. ruby - 在 jRuby 中使用 'fork' 生成进程的替代方案? - 2

    在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',

  6. ruby - 如何使用 Ruby aws/s3 Gem 生成安全 URL 以从 s3 下载文件 - 2

    我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A

  7. ruby-on-rails - Rails HTML 请求渲染 JSON - 2

    在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这

  8. ruby-on-rails - 如果 Object::try 被发送到一个 nil 对象,为什么它会起作用? - 2

    如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象

  9. ruby - 为什么 SecureRandom.uuid 创建一个唯一的字符串? - 2

    关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion为什么SecureRandom.uuid创建一个唯一的字符串?SecureRandom.uuid#=>"35cb4e30-54e1-49f9-b5ce-4134799eb2c0"SecureRandom.uuid方法创建的字符串从不重复?

  10. ruby-on-rails - Rails - 从另一个模型中创建一个模型的实例 - 2

    我有一个正在构建的应用程序,我需要一个模型来创建另一个模型的实例。我希望每辆车都有4个轮胎。汽车模型classCar轮胎模型classTire但是,在make_tires内部有一个错误,如果我为Tire尝试它,则没有用于创建或新建的activerecord方法。当我检查轮胎时,它没有这些方法。我该如何补救?错误是这样的:未定义的方法'create'forActiveRecord::AttributeMethods::Serialization::Tire::Module我测试了两个环境:测试和开发,它们都因相同的错误而失败。 最佳答案

随机推荐