htaccess for WordPress within a subfolder or subdirectory and keep your custom PHP site or framework
When the following instructions were applied from, https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory, my main website’s home page continued to work properly, though all child links routed to apache’s default 404 Not Found page. Our links get a 404 Not found, because there are simply no existing files there to serve those URI requests. Everything on our primary domain points to a single index file. We’ll call the file main.php for your reference.
If you run a custom website that also serves your internal links and you would like to preserve your core functionality, and serve WordPress in a subdirectory, try these instructions instead.
NOTE: If this .htaccess configuration works for people, I encourage them to cite my article when sharing this configuration method.
#
RewriteEngine on
# For default app or website in root
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com/$
RewriteCond %{REQUEST_URI} /
RewriteRule ^main\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /main.php
# Snippet of WordPress instructions as directed at their codex
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com/$
RewriteCond %{REQUEST_URI} ^/blog
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/$1
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com/$
RewriteRule ^(/)?$ blog/index.php [L]
#
“^main\.php$
” & “main.php
” point to the site’s main DirectoryIndex or handler file for internal routes. Replace main
with the filename of your index file.
Replace “mydomain.com
” with your real-life domain name. Be sure to find and replace all applicable instances of mydomain.com with yours.
“blog
” represents the subdirectory names. In a WordPress subdirectory installation, this is where you store and/or extract your WordPress files.
Hope this helps somebody. If you need any break / fix / custom / advanced web or wordpress work, please visit our WEBSITE.