Mod-rewrite extensionless URLs with extension within directory separate from WordPress install

I am trying to help a nonprofit with their website that they recently moved to WordPress but they have some legacy PHP pages that they still need.

I have migrated all of these pages over into a separate directory from WordPress; however, I am having issues with the URL rewriting.

Read More

They refer to these links without the .php extension (website.com/directory/page) and I cannot get the .htaccess mod-rewrite rules in the directory to add the .php extension so they will load and instead I get a 404 redirect. I want it to load website.com/directory/page/php.

I have tried several variations of the below .htaccess rewrite rules:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

I think it may have something to do with the WordPress install and the rewrite rules associated with it; however, I thought that any .htaccess file in a directory took precedence.

I have searched and searched and tried every variation I could find and unfortunately I have only limited experience with regular expressions.

Maybe there is a problem a the vhost level? I either get a server error or a redirect.

Related posts

Leave a Reply