5

On a subdirectory such as http://website.com/sub/index.html that has it's own .htaccess is still for some reason showing the 404 page I have for Wordpress which is on the directory above this one.

.htaccess for sub dir:

ErrorDocument 404 /404.html

.htaccess for main dir:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^website.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.website.net$
RewriteRule ^foghelper.php$ http://website.net/subdirone/ [R=301,L]
RewriteRule ^foghelper.php$ http://website.net/subdirtwo/ [R=301,L]
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE jNLK5d:REDIRECTID


# 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

Links that were in the hta were censored in case your wondering.

Edit:

Upon adding RewriteCond %{REQUEST_URI} !^/?sub/ before RewriteRule . /index.php [L] the error still seems to exist.

Jesse Nickles
  • 1,435
  • 1
  • 17
  • 25
ComputerLocus
  • 3,448
  • 10
  • 47
  • 96
  • Have you seen this post? http://stackoverflow.com/questions/2322559/htaccess-wordpress-exclude-folder-from-rewriterule Hope it helps! – jmlv21104 Jan 15 '13 at 16:23

2 Answers2

0

Everything is being routed through wordpress so when a request for something like /sub/no_file.html and it doesn't exist, wordpress routes it through its index.php because it satisfies both the !-f and !-d conditions (not an existing file and not an existing directory). It then decides that it can't find the resource for /sub/no_file.html so it then displays its own 404 file.

If you want requests that go to /sub to bypass wordpress' routing so that if a file is requested in /sub/ that doesn't exist, /404.html gets served, you can add this line right before RewriteRule . /index.php [L] in your wordpress rules so that they look like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/?sub/
RewriteRule . /index.php [L]
</IfModule>
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
0

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.

jmlv21104
  • 89
  • 12
  • 1
    No, you see what I want to do is have sub directories, such sitename.com/subdir utilize its own 404 page. On my website certain web apps I have are on different directories, and they all have their own 404 that goes with the theme and such. Yet whenever I go to pages in these directories that do not exist, I am taken to the wordpress 404 error on the main directory. – ComputerLocus Jan 16 '13 at 19:16