1

Let me explain by example...

File: /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>

File: /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>

For performance, I want to disable use of .htaccess on my server, and use the httpd.conf configuration file instead, which is what you can see above.

The thing is, the .htaccess rule which is placed in the specific directory (/var/www/example.com/public/wp-content/cache/minify/) works, but the same rule in my httpd.conf file doesn't. I am not sure why. What could I be doing wrong here?

  • Do you have the same DocumentRoot in your httpd.conf as in your .htaccess? – Jenny D Sep 23 '13 at 12:15
  • You have four rules there. Which one isn't working? And what does it do when it doesn't work? – Ladadadada Sep 23 '13 at 12:27
  • @JennyD As stated in the question, the .htaccess file is located in '/var/www/example.com/public/wp-content/cache/minify/'. As for the httpd.conf, note the <Directory /var/www/example.com/public> and RewriteBase /wp-content/cache/minify/ for the mod_rewrite rule, which, I believe, should be equivalent. – its_me Sep 23 '13 at 12:43
  • 1
    No, you have commented the .htaccess file with # THIS WORKS... and the httpd.conf file with # BUT THIS ISN'T WORKING!!!. Both files have four rewrite rules in them and one of the rules is preceded by a rewrite condition. You also don't explain what happens when the rule doesn't work. It might help to also give an example URL that you expect to match one of the rewrite rules. – Ladadadada Sep 23 '13 at 12:58
  • 1
    @Ladadadada Ah, guess I misunderstood. :) Okay, this is an example URL: http://example.com/wp-content/cache/minify/000000/877fd/default.include-footer.489f00.js -- it's supposed to work, but it returns a 404 error as the rules aren't working. (Is that what you asked for?) – its_me Sep 23 '13 at 13:00
2

Not sure if this is the best way to do it, but it works. Essentially, it needs the RewriteEngine On rule in the second <Directory> section as well.

File: /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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.