Search code examples
wordpressapache.htaccessmod-rewritehttp-status-code-403

403 error on wordpress install on subdirectory


I have a website with the following structure:

/public_html
    /main site content (html content mostly)
    /.htaccess (1)
    /secret (dir)
        /wp (dir)
            /a wordpress install
            /.htaccess (2)

/secret/wp/ is meant to be a development site for moving to a wordpress solution. It's where I'm working on the new site.

The root .htaccess is causing 403 Forbidden errors when I try to view the new site. I know this because deleting it from the server fixes the issue.

The problem is, it's doing some important file extension name rewrites for me that I need or else my main site breaks.

htaccess (1)

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>

DirectoryIndex index.html

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteRule ^(wp-admin)($|/) - [L] # You don't want to mess with WordPress 
 RewriteRule ^/secret/wp/ - [L]
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME}\.html -f
 RewriteRule .* $0.html

 # browser requests html
 RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.html
 RewriteRule ^/?(.*)\.html$ /$1 [L,R=301]

 # check to see if the request is for a html file:
 RewriteCond %{REQUEST_FILENAME}\.html -f
 RewriteRule ^/?(.*)$ /$1.html [L]
</IfModule>

Redirect 301 /shop.html https://mydomain.myshopify.com/

Adding the line "RewriteRule ^/secret/wp/ - [L]" was the result of searching for a solution to this issue, but it doesnt seem to do anything.

My other .htaccess seems to not be triggering at all. I will post it for clarity:

.htaccess (2)

# BEGIN WordPress
<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteBase /secret/wp/

    RewriteRule ^index\.php$ - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule . /secret/wp/index.php [L]

    # Fix 403 errors on existing directories; WordPress overrides.
        RewriteCond %{REQUEST_URI} ^/secret/wp/
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule . /index.php [L]

</IfModule>
# END WordPress

I'm at a loss for what to do. I can't just delete the .htaccess file or else the whole site breaks, but I can't seem to figure out how to stop the 403 errors. I'm pretty sure it's because of the rewrite rule, but it doesn't seem to be stopping for the directory like its supposed to.

Any help would be greatly appreciated.


Solution

  • Found the answer. It took a week of digging and testing through every possible forum I could find, but eventually (after deleting the whole wp install and reinstalling to a clean directory), I found the simplest answer that fixed it all:

    I had to edit my .htaccess file to allow "index.php" as a valid default index page.

    My .htaccess file for the top level of my domain only had this line: DirectoryIndex index.html

    I just had to change it to DirectoryIndex index.html index.php

    And then everything worked.