微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在用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";

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐