How To Fix: Redirect WordPress (installed in a directory) to main web address?
Sometimes you may want to install WordPress into one of your folders like your-website.com/blog for future-proofing, or you know that your main page will contain something else. I had this problem when creating my blog, I’ve tried to use domain redirection to the blog page, but it creates a massive amount of redirections and ultimately failed. Don’t use them in this case.
If You look from the user point of view, all I wanted is to type my website address (www.)your-website.com and have it redirected to /blog folder. The root directory for the site is your-website.com/, but the root for WordPress is /blog, so when you type your webpage name, it will list a folder in the web browser. We don’t want that.
Go to Settings in WordPress and see if Your settings below are the same, keep the Setting page open:
WordPress Address (URL): https://www.your-website.com/blog
Site Address (URL): https://www.your-website.com/blog
If you still use HTTP:// instead of secure HTTPS:// version then You should find out how to change it.
Log in via FTP to your site or if you are using BlueHost like me, log in to your Domain account, then Advance option, followed by File Manager and find Your blog/ folder. COPY (do not move it) the .htaccess and index.php to the main root of your website. When you are connecting to the site via a browser, it first looks for the index file. Edit .htaccess file and see if RewriteBase /blog/ is there, if not change RewriteBase / to RewriteBase /blog/ so it’s pointing to your actual WordPress installation.
Go to the root directory of your website and start editing Your new copy of index.php. Change the line:
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
to the folder, that has your WordPress installation, in our case /blog/
require( dirname( __FILE__ ) . '/blog/wp-blog-header.php' );
Save the index.php.
Login to WordPress admin account via https://www.your-website.com/blog/wp-admin/ check the Site Address, it should be your full web address without the installation folder: https://www.your-website.com. Sometimes you may have a problem with some pages not being accessible and with Error 404 on your blog. In this case, keep those addresses the same with installation folder like https://www.your-website.com/blog/ and try again opening this page. If everything went ok, you should be able to type your web address https://your-website.com and be redirected to https://www.your-website.com/blog/. If you use permalinks, go to Settings and update them as well. Don’t forget to copy the .htaccess file to your main folder to update the changes. Those files will not be auto-updated when you do changes, and you have to do it yourself.