I refer to this question previously asked and not suitably answered: Wordpress overriding actual subdirectories and also Non "Wordpress" pages/code getting 404 error

I have the same problem and I have tried nearly everything I found on the net. It's definitely related to having permalinks turned on in the wordpress. However, I have put a new .htaccess file in the subdirectory with:

RewriteEngine off

and the problem still exists. Even if I completely delete the wordpress .htaccess file the problem still exists.

I have also tried some other suggested solutions such as ErrorDocument 401 "Unauthorized access" and ErrorDocument 404 "Unauthorized access" and Redirect 301 /mysubdirectory http://www.mydomain.com/mysubdirectory/index.html in various locations all to no avail.

Can someone please offer another solution? The only way I can fix it is to turn permalinks off but we need them to be on.



  • What happens if you rename the index.php to index.bak in the WordPress root folder? Is the directory still not accessible? – Horttcore Jun 16 '11 at 8:44
  • Have you tried to redefine the base url in your sub-folder .htaccess (with this sub-folder for value) ? – Cédric G Aug 5 '11 at 15:19

I'm assuming that you put WordPress in your site root and the external directories are also in your site root. The reason this is happening is that .htaccess files follow a hierarchy. Whatever directives are in the top-level .htaccess file flow down and apply to all directories below it.

If this is the case, you can do one of several things:

  1. Move your WordPress into its own directory. See: http://codex.wordpress.org/Moving_WordPress If you move WordPress into its own directory so that it is on the same level in your server directory hierarchy as the other directories the WordPress rewrite rules cannot affect the other directories.

  2. RewriteEngine Off - this would normally work. If it isn't working check that you are not using a wildcard DNS setting. If you have a wildcard * hostname record pointing at your web server in your DNS settings it can cause havoc with .htaccess and subdomains.

  3. In the .htaccess file in your site root, add the following ABOVE the WordPress .htaccess directives:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^/subdirectoryname1/(.*)$ [OR]
    RewriteCond %{REQUEST_URI} ^/subdirectoryname2/(.*)$ [OR]
    RewriteRule ^.*$ - [L]

One of these should work for you.


This has worked for me in the past for a similar situation :

Put this on top of .htaccess

ErrorDocument 401 default
  • 3
    Thanks! I've tried so many things, but this is the only solution that worked for my case: password-protected subdirectory – Rado Mar 6 '13 at 23:27
  • 2
    Worked for me too, any explanation as to what it does and why it works? – Asaf Aug 10 '13 at 8:27
  • This works for me.. not using wordpress but OpenCart and having the same problem. An explanation would be really helpful. – billynoah Aug 28 '14 at 19:09

when i copy my files into the same server but with different subdirectory folder so when i tried to access my pages, index.php is working fine but the other pages are not and giving me a 404 error. Sorry for my bad english!!

I just look into my htaccess the original:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

and put the new one with

# BEGIN WordPress

RewriteEngine On
RewriteBase /subdirectoryfolder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirectoryfolder/index.php [L]

# END WordPress
  • Hi @lizette. Welcome to WPSE forums. You may want to check out how formatting works here. – Pothi Kalimuthu Sep 21 '12 at 2:59
  • Just be careful that you never change the permalink structure, because when you do that, WP will overwrite anything between #BEGIN WordPpress and #END WordPress – clayRay Oct 13 '20 at 3:53

I see this thread is a few months old, but just in case you never got it to work!

I had a similar issue, but my problem was that the wordpress install was located in the subdirectory which prevented URL access to folders within the root (outside the WP install directory), but only when permalinks were enabled. To solve this, I copied both index.php and .htaccess (copy not move) from the subdirectory where the WP install is located and placed them both in the root public_html (or whatever subdirectory that you're trying to access outside the WP install directory). The .htaccess file has the rewrite conditions for permalinks already:

RewriteEngine On
RewriteBase /subdirectoryinstallfolder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Enable permalinks for refresh and it solved all issues. Make sure your permissions for the root folders are set correctly too as this has caused me problems in the past.


If you are still getting 404's with the htaccess disabled and you have verified the paths and you know the files are there then your only options left are these three...


  1. Server is quite possibly running a case-sensitive operating system. Which means if you are typing in a path and not using the exact characters and casing it simply will not work.
  2. Permissions: You may have the wrong permissions on the file or folder or a parent folder. Try to change the permissions to 755 on the files, folders, and parent folders. If you have ssh (terminal) access to it then go to your root and run this "chmod -R 755 mydir" and that will recursively set the permissions for all of them.
  3. If you are still having a problem after all of that then you have a server config problem (Apache probably). You will need to talk to your hosting provider about it.

If none of that works then you need a new host.


After nearly plucking my hair editing the htaccess I finally found a solution that will work for WordPress.

I had this problem after installing a codeiginter script on the same root directory that WordPress is installed.

After trying all the tricks listed here I was still getting 404 errors on the pages associated with the new script.

I noted that the WordPress htaccess was overiding the script's htaccess. I also noted that other WordPress installations in the same directory did not have this 404 error.

I simply adopted the htaccess from the new WordPress installation in the same server directory and added it in the folder where my script is located. Here is how it looks like :

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

Replace subdirectoryname with the name of your directory and place this htaccess file inside the folder where your script is located.

Example : If the site is installed here


and the new folder is located


copy the htaccess above and save it inside the folder 'example' and this should work.


I've looked at the responses here a number of times as I'd run into a similar problem. I have files in a subdirectory that would throw a 404 error when I tried to access them. All the .htaccess stuff failed to rectify it, as Kirsten Douglas says, Wordpress does the job already.

My solution

I found this article after checking the error_log on the server. I was getting a message about wrong uid for scripts. I also noticed that the 404 wasn't being thrown because of the file, but because the server couldn't serve up a 500.html file i.e. I had a 500 error.

Turns out I'd created files as root, and needed to change ownership to the webfiles owner.

I hope this helps others who've had the same issue!


You should be able to just add a RewriteCond directive that will make sure the WordPress rules are ignored for requests inside your subfolder.

RewriteCond %{REQUEST_URI} !^/mysubdirectory
# rest of WordPress rewrite rules

However, you say that even with no WordPress .htaccess you're experiencing the problem? What's the contents of your subdirectory .htaccess?

Not the answer you're looking for? Browse other questions tagged or ask your own question.