0

It seems that Wordpress has changed the default .htaccess file so that you can no longer run different PHP code within the a subfolder. It also states that the block in the .htaccess file is dynamically created, so messing with it directly would be problematic.

So what is the correct way to support running other PHP code that isn't related to Wordpress in a subfolder that Wordpress is installed?

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
4
  • "It seems that Wordpress has changed the default .htaccess file so that you can no longer run different PHP code within the same folder." At least for me, this doesn't seem to be the case. For example, I can have a foo.php in the folder next to the .htaccess and navigate to it via /foo.php and it will run.
    – Wongjn
    Commented Jun 8 at 18:14
  • I should note, this is for a subfolder. I will update the question.
    – Exit
    Commented Jun 8 at 21:44
  • "It seems that Wordpress has changed the default .htaccess file so that you can no longer run different PHP code within the (sic) a subfolder." At least for me, this doesn't seem to be the case. For example, I can have a foo.php in some arbitrary subfolder and navigate to it via /some/arbitrary/folder/foo.php and it will run.
    – Wongjn
    Commented Jun 8 at 21:54
  • It isn't the case for me, so I'm not sure what it is.
    – Exit
    Commented Jun 11 at 18:42

1 Answer 1

0

To run non-WordPress PHP files in a subfolder alongside a WordPress installation, follow these steps to modify your .htaccess file:

  1. Choose a Subfolder Name: Decide the name for your subfolder, e.g., mycustomphp.

  2. Modify the .htaccess File: Add the following lines above the # BEGIN WordPress section to exclude your subfolder from WordPress's URL rewriting:

    RewriteEngine On
    RewriteRule ^mycustomphp/ - [L]
    

    Ensure the entire .htaccess looks like this:

    RewriteEngine On
    RewriteRule ^mycustomphp/ - [L]
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    

This approach allows your PHP files to operate separately from the WordPress environment without altering core rewrite rules that could affect your main site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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