I have the following .htaccess in my root:

DirectoryIndex index.html index.php
Options +Indexes

# 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]

# END WordPress

I want to add the following rule for everything under the /account folder:

ErrorDocument 404 /error.php

I believe it should start with RewriteCond %{REQUEST_URI} !^/account but I'm not sure how to write the actual rule nor where in the document to add this.

Any help is much appreciated.

EDIT: I tried in /account/.htaccess :

ErrorDocument 404 /error.php

# Enable the rewrite engine in the subdirectory to prevent
# mod_write directives in the parent .htaccess file being executed.
RewriteEngine On
RewriteOptions inherit
  • The fastest and easiest way to do this is to create an .htaccess file within your /account directory with the rules you want. – closetnoc Jun 14 '15 at 4:39
  • @closetnoc, I tried this but it didn't work. When removing the whole Wordpress rule from the root .htaccess it affected the /account pages even though there is a custom .htaccess file in /account – Chris Jun 14 '15 at 4:43
  • Is /account intended to be outside of WordPress? Simply including the ErrorDocument directive inside /account/.htaccess is not going to work because the WordPress mod_rewrite directives in the parent .htaccess file are going to override requests for non-existent-files (rewriting all requests to index.php). You either need to break the association with WordPress, for the /account folder, or incorporate alternative directives in the main .htaccess file - although this might not be so easy since WordPress normally handles 404s. What is the actual goal here? – MrWhite Jun 14 '15 at 12:20
  • Ah, I've just noticed the title! Is this really a subdomain? – MrWhite Jun 14 '15 at 13:01
  • @w3d, yes it's a subdomain. The subdomain is running a separate platform from wordpress (that I am coding) and I want that (sub)site to have a separate 404 behaviour than that of the wordpress site. -- sorry if I didn't make it clear it's a subdomain. – Chris Jun 14 '15 at 16:18

If the /account subfolder is intended to be outside of WordPress then you can do something like closetnoc suggests, however, you also need to enable the rewrite engine to prevent the WordPress rewrites in the parent .htaccess from taking over.

So, in /account/.htaccess:

ErrorDocument 404 /error.php

# Enable the rewrite engine in the subdirectory to prevent
# mod_write directives in the parent .htaccess file being executed.
RewriteEngine On

Simply enabling the rewrite engine in the subdirectory will prevent mod_write directives in the parent .htaccess file being executed. Since mod_rewrite directives are not inherited by default. In order to "inherit" parent directives you would need to explicitly call: RewriteOptions inherit.

The fact that it's a subdomain doesn't really make a difference in this respect.

  • Many thanks for your reply @w3d, but this doesn't seem to work. I tried entering an incorrect url (account.domain.com/index.phpp) and (domain.com/account/index.phpp) but these yield different results. The first one just loads account.domain.com/index.php and the second one takes me to the wordpress 404-page. – Chris Jun 14 '15 at 16:27
  • I edited my question to show what I tried in /account/.htaccess – Chris Jun 14 '15 at 16:30
  • Don't include RewriteOptions inherit (as you've included in your question) - that will certainly produce the results you are experiencing, which is not desirable is this instance. The bit I wrote about RewriteOptions was for background information only, you don't want to "inherit" the parent (WordPress) directives. Also, try an entirely incorrect URL eg. /this-does-not-exist.php. – MrWhite Jun 14 '15 at 16:38
  • Does /index.phpp externally redirect to /index.php? - Not sure why that would happen, unless there is something else going on? – MrWhite Jun 14 '15 at 17:01
  • The url in the browser still displays index.phpp but it definetly loads the default index.php. – Chris Jun 14 '15 at 17:13

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.