2

我有一个不解释 CSS 的网站。我已经看到了其他答案,但没有看到动态生成的 css 的答案。我通过添加在 PHP 中生成 CSS

<link media="all" type="text/css" href="http://tylldalil.wconsult.no/?ai1ec_render_css=1367403986&ver=3.5.1" id="ai1ec_stytle-css" rel="stylesheet">

我在 php 中的函数

public function render_css() {
     header( 'Content-Type: text/css' );
    // Aggressive caching to save future requests from the same client.
    $etag = '"' . md5( __FILE__ . $_GET[self::GET_VARIBALE_NAME] ) . '"';
    header( 'ETag: ' . $etag );
    $max_age = 31536000;
    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 ( extension_loaded( 'zlib' ) ) {
            // ob_start( 'ob_gzhandler' );
        }
        $content = $this->get_compiled_css();
        echo $content;
        ob_end_flush();
    } else {
        // Not modified!
        status_header( 304 );
    }
    // We're done!
    exit( 0 );
}

这是我的 htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?tlldalil.wconsult.no$
RewriteRule ^(/)?$ ?page_id=23 [R=301,L]

order deny,allow
deny from all
allow from 88.89.104.103 
allow from 93.50.99.14



###Start Kloxo PHP config Area
###Please Don't edit these comments or the content in between. kloxo uses this to recognize the lines it writes to the the file. If the above line is corrupted, it may fail to recognize them, leading to multiple lines.

<Ifmodule mod_php4.c>
    php_value error_log "/home/klausen/__processed_stats/tylldalil.wconsult.no.phplog"
    php_value upload_max_filesize 64M
    php_value max_execution_time  60
    php_value max_input_time  120
    php_value memory_limit  64M
    php_value post_max_size  64M
    php_flag register_globals  off
    php_flag display_errors  off
    php_flag file_uploads  on
    php_flag log_errors  off
    php_flag output_buffering  off
    php_flag register_argc_argv  on
    php_flag magic_quotes_gpc   off
    php_flag magic_quotes_runtime  off
    php_flag magic_quotes_sybase  off
    php_flag mysql.allow_persistent  off
    php_flag register_long_arrays  on
    php_flag allow_url_fopen  on
    php_flag cgi.force_redirect  on
    php_flag enable_dl  on
</Ifmodule>

<Ifmodule mod_php5.c>
    php_value error_log "/home/klausen/__processed_stats/tylldalil.wconsult.no.phplog"
    php_value upload_max_filesize 64M
    php_value max_execution_time  60
    php_value max_input_time  120
    php_value memory_limit  64M
    php_value post_max_size  64M
    php_flag register_globals  off
    php_flag display_errors  off
    php_flag file_uploads  on
    php_flag log_errors  off
    php_flag output_buffering  off
    php_flag register_argc_argv  on
    php_flag magic_quotes_gpc   off
    php_flag magic_quotes_runtime  off
    php_flag magic_quotes_sybase  off
    php_flag mysql.allow_persistent  off
    php_flag register_long_arrays  on
    php_flag allow_url_fopen  on
    php_flag cgi.force_redirect  on
    php_flag enable_dl  on
</Ifmodule>

###End Kloxo PHP config Area




# BEGIN WordPress

# END WordPress

我应该在我的 htaccess 中添加什么?

4

2 回答 2

1

当我尝试查看您的 CSS 时,我得到一个“由 CentOS 提供支持的 Apache 2 测试页面”HTML 页面。页面响应标头声明“403 Forbidden”。

这可能与您的激进缓存有关吗?

如果在您的 PHP 中修改以下行会发生什么情况:

$etag = '"' . md5( __FILE__ . $_GET[self::GET_VARIBALE_NAME] ) . '"';

$etag = '"' . md5( __FILE__ . $_GET[self::GET_VARIABLE_NAME] ) . '"';

?

于 2013-05-21T21:43:48.837 回答
0

您在 php 中设置了 Content-type,但似乎服务器为该脚本强制使用了另一个 Content-type。您可以尝试为您的脚本设置 css 扩展名并使用 mod_rewrite 重写它:

<link media="all" type="text/css" href="http://tylldalil.wconsult.no/css_1367403986_ver_3.5.1.css" id="ai1ec_stytle-css" rel="stylesheet">

在 .htaccess 中:

RewriteEngine On

RewriteCond %{ENV:REDIRECT_FINISH} !^$
RewriteRule .* - [L]

RewriteCond %{REQUEST_FILENAME}  !-f
RewriteRule css_([0-9])+_ver_([0-9.]+)\.css$ ?ai1ec_render_css=$1&ver=$2 [E=FINISH:1,L]

RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^(/)?$ ?page_id=23 [R=301,L]
于 2013-05-22T11:36:07.177 回答