RewriteBase 规则在 .htacess 中有效,但在 httpd.conf 中无效(在)?

RewriteBase 规则在 .htacess 中有效,但在 httpd.conf 中无效(在)?

让我举例解释一下……

文件:/var/www/example.com/public/wp-content/cache/minify/.htaccess

<IfModule mod_rewrite.c>

    # THIS WORKS...
    RewriteBase /wp-content/cache/minify/
    RewriteRule /w3tc_rewrite_test$ ../../plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 [L]
    RewriteCond %{REQUEST_FILENAME}%{ENV:APPEND_EXT} -f
    RewriteRule (.*) $1%{ENV:APPEND_EXT} [L]
    RewriteRule ^(.+/[X]+\.css)$ ../../plugins/w3-total-cache/pub/minify.php?test_file=$1 [L]
    RewriteRule ^(.+\.(css|js))$ ../../plugins/w3-total-cache/pub/minify.php?file=$1 [L]

</IfModule>

文件:/etc/apache2/httpd.conf

<Directory /var/www/example.com/public>

    AllowOverride None

    Options -MultiViews

    [...]

    <IfModule mod_rewrite.c>
        Options +FollowSymlinks
      # Options +SymLinksIfOwnerMatch
        RewriteEngine On
      # RewriteBase /
    </IfModule>

    [...]

    <IfModule mod_rewrite.c>

        # BUT THIS ISN'T WORKING!!!
        RewriteBase /wp-content/cache/minify/
        RewriteRule /w3tc_rewrite_test$ ../../plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 [L]
        RewriteCond %{REQUEST_FILENAME}%{ENV:APPEND_EXT} -f
        RewriteRule (.*) $1%{ENV:APPEND_EXT} [L]
        RewriteRule ^(.+/[X]+\.css)$ ../../plugins/w3-total-cache/pub/minify.php?test_file=$1 [L]
        RewriteRule ^(.+\.(css|js))$ ../../plugins/w3-total-cache/pub/minify.php?file=$1 [L]

    </IfModule>

    [...]

</Directory>

为了提高性能,我想在我的服务器上禁用 .htaccess,而改用 httpd.conf 配置文件,这就是您在上面看到的。

问题是,放置在特定目录 (/var/www/example.com/public/wp-content/cache/minify/) 中的 .htaccess 规则有效,但我的 httpd.conf 文件中的相同规则无效。我不确定为什么。我在这里可能做错了什么?

答案1

不确定这是否是最好的方法,但它确实有效。本质上,它也需要RewriteEngine On第二部分中的规则。<Directory>

文件:/etc/apache2/httpd.conf

<Directory /var/www/example.com/public>
    AllowOverride None
    Options -MultiViews

    [...]

    <IfModule mod_rewrite.c>
        Options +FollowSymlinks
      # Options +SymLinksIfOwnerMatch
        RewriteEngine On
      # RewriteBase /
    </IfModule>

    [...]
</Directory>

<Directory /var/www/example.com/public/wp-content/cache/minify>
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /wp-content/cache/minify/
        RewriteRule /w3tc_rewrite_test$ ../../plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 [L]
        RewriteCond %{REQUEST_FILENAME}%{ENV:APPEND_EXT} -f
        RewriteRule (.*) $1%{ENV:APPEND_EXT} [L]
        RewriteRule ^(.+/[X]+\.css)$ ../../plugins/w3-total-cache/pub/minify.php?test_file=$1 [L]
        RewriteRule ^(.+\.(css|js))$ ../../plugins/w3-total-cache/pub/minify.php?file=$1 [L]
    </IfModule>
</Directory>

相关内容