Apache-2.2

RewriteBase 規則在 .htacess 中有效,但在 httpd.conf 中無效(在 <Directory …> 內)?

  • September 23, 2013

讓我舉例說明…

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

&lt;IfModule mod_rewrite.c&gt;

   # 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]

&lt;/IfModule&gt;

文件: /etc/apache2/httpd.conf

&lt;Directory /var/www/example.com/public&gt;

   AllowOverride None

   Options -MultiViews

   [...]

   &lt;IfModule mod_rewrite.c&gt;
       Options +FollowSymlinks
     # Options +SymLinksIfOwnerMatch
       RewriteEngine On
     # RewriteBase /
   &lt;/IfModule&gt;

   [...]

   &lt;IfModule mod_rewrite.c&gt;

       # 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]

   &lt;/IfModule&gt;

   [...]

&lt;/Directory&gt;

為了提高性能,我想在我的伺服器上禁用 .htaccess,並改用 httpd.conf 配置文件,這就是您在上面看到的。

問題是,放置在特定目錄(/var/www/example.com/public/wp-content/cache/minify/)中的 .htaccess 規則有效,但我的 httpd.conf 文件中的相同規則沒有噸。我不確定為什麼。我在這裡做錯了什麼?

不確定這是否是最好的方法,但它確實有效。本質上,它也需要RewriteEngine On第二&lt;Directory&gt;部分中的規則。

文件: /etc/apache2/httpd.conf

&lt;Directory /var/www/example.com/public&gt;
   AllowOverride None
   Options -MultiViews

   [...]

   &lt;IfModule mod_rewrite.c&gt;
       Options +FollowSymlinks
     # Options +SymLinksIfOwnerMatch
       RewriteEngine On
     # RewriteBase /
   &lt;/IfModule&gt;

   [...]
&lt;/Directory&gt;

&lt;Directory /var/www/example.com/public/wp-content/cache/minify&gt;
   &lt;IfModule mod_rewrite.c&gt;
       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]
   &lt;/IfModule&gt;
&lt;/Directory&gt;

引用自:https://serverfault.com/questions/540956