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?

7
  • Do you have the same DocumentRoot in your httpd.conf as in your .htaccess? Commented Sep 23, 2013 at 12:15
  • You have four rules there. Which one isn't working? And what does it do when it doesn't work? Commented Sep 23, 2013 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. Commented Sep 23, 2013 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. Commented Sep 23, 2013 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?) Commented Sep 23, 2013 at 13:00

1 Answer 1

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> 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.