Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

in /www/ I have an .htaccess file containing:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^([^.]*\.less)$ compilers/lessphp.php?file=$1 [R,QSA,L]
</ifModule>

This code works fine, until I'm requesting .less files in /www/blog/, where WordPress is located, and has its own .htaccess file which contains the standard pretty permalinks mod_rewrite:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
</IfModule>

If I move WordPress's mod_rewrite code to the root, and place it before my own mod_rewrite, everything works as expected:

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

# BEGIN LESSPHP
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^([^.]*\.less)$ compilers/lessphp.php?file=$1 [R,QSA,L]
</ifModule>
# END LESSPHP

The annoyance here, is any modification in WordPress to do with permalinks means I need to remember to cut the .htaccess code from /www/blog/ and move it to the root.

Is there any way I can improve upon my mod_rewrite so WordPress isn't overwriting it, and I can just leave everything where it is naturally placed? I would also rather not need to have two instances of my rule in both root and after WordPress's. Also, WordPress's mod_rewrite rules should be altered, since updating permalink settings will simply overwrite them.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

A quick fix could be to change the permissions on your .htaccess file so if you change settings in Wordpress, it'll show you what you need to manually change your .htaccess to since it won't have direct write access to the file anymore.

share|improve this answer
1  
That's a good point actually! –  user19606 Sep 4 '12 at 21:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.