Access a custom PHP page, without getting the WordPress 404 Page Not Found

Not exactly rocket science, here, but I thought I’d post this, which was a little something that took me WAY to long to figure out today. :-)

Basically, I had a custom script in a subdirectory of a wordpress intsall which needed to be accessed in the browser directly. Naturally, requests for PHP files are rewritten to the WordPress index by the .htaccess file in the root directory, which results in a Page Not Found page when trying to access your script. To get around this, a condition needs to be added to the rewrite rules. The standard mod_rewrite rules looks something like this:


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

The following line can be added just before the rewrite rule to ignore a directory named “custom.”


RewriteCond %{REQUEST_URI} !^/(custom) [NC]

So… the complete block looks like this, and now my pretty PHP page in the “custom” directory can be access in the browser.


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
##don't rewrite requests to the custom script
RewriteCond %{REQUEST_URI} !^/(custom) [NC]
RewriteRule . /index.php [L]
</IfModule>
This entry was posted in Web Development and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.