Apache-2.2
RewriteBase 規則在 .htacess 中有效,但在 httpd.conf 中無效(在 <Directory …> 內)?
讓我舉例說明…
文件: /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 文件中的相同規則沒有噸。我不確定為什麼。我在這裡做錯了什麼?
不確定這是否是最好的方法,但它確實有效。本質上,它也需要
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>