让我通过例子来解释…
文件: /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.confconfiguration文件,这是你可以在上面看到的。
事情是,位于特定目录(/var/www/example.com/public/wp-content/cache/minify/)中的.htaccess规则起作用,但是在我的httpd.conf文件中同样的规则不会'吨。 我不知道为什么。 我在这里做错了什么?
不知道这是否是最好的办法,但它的工作。 实际上,它也需要第二个<Directory>部分中的RewriteEngine On规则。
文件: /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>