htaccess disable WordPress rewrite rules for folder and its contents

I have another PHP application in a folder named app inside my WordPress installation, and I need to disable all WordPress rewrite rules for that folder and it’s content. So that when I go to www.domain.com/app I get my application page, instead of the standard WordPress 404 page.

I know this is pretty basic apache rewrite rules, and i searched for this, tried some things and didn’t work well.

Read More

Almost forgot, i need to do this only by editing WordPress htaccess file. And the app has it’s own htaccess file.

Thanks.

EDIT: htaccess content

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

EDIT: Application htaccess

DirectoryIndex index.php
<FilesMatch ".(php|inc)$">
Order allow,deny
deny from all
</FilesMatch>
<FilesMatch "(index.php|download.php)$">
Order allow,deny
allow from all
</FilesMatch>

These rules don’t do much, they basically deny access to all PHP and INC file types, except index.php and download.php. Which are the ones the user needs to access, the rest of them are classes used internally by PHP.

EDIT 3: Resolution:

As it turns out, there was nothing wrong with the WordPress htaccess or the application, after turning error reporting on remote hosting server, PHP reported a corrupted file, once replaced, all started to work well. My thanks to Wietse Venema for the suggestion.

Related posts

Leave a Reply

1 comment

  1. The default .htaccess-file will already support the behaviour you want;

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

    The magic is in the lines that start with RewriteCond. They instruct Apache to apply the rule RewriteRule . /index.php [L] (which means “any URL will go to index.php”), only when the URL is not an existing file !-f or existing directory !-d.

    So this should work by default. The WordPress rewrite rules do not apply when you try to visit an already existing file.