Overview
This article explains how to redirect requests to the primary website URL (example.com) to a subdirectory (example.com/blog).
See this article for instructions on how to create an .htaccess file on your web server.
If the file already exists, view the following articles for instructions on how to update it (depending on if you're using an FTP client or SSH):
Redirecting requests
The examples below can be entered into your .htaccess file exactly as shown. Only if the example contains a URL (example.com) should you change it to your actual URL.
Redirect "ALL" requests
This example redirects all requests for a website automatically to a subdirectory named /blog. If you need to redirect to another directory, just change the two references of /blog to your subdirectory.
- Log in to your server via FTP.
- Upload (or create) a text file named .htaccess (with no extension).
- Place the file in the website directory.
- Add the following content to the .htaccess file:
RewriteEngine on RewriteBase /
# Rewrites all URLS without blog in them RewriteCond %{REQUEST_URI} !^/blog/ # Rewrites all URLS. Replace "example" with your domain, without the TLD (.com, .net). RewriteCond %{HTTP_HOST} ^(www\.)?example\. # Rewrite all those to insert /folder RewriteRule ^(.*)$ /blog/$1 [L]
Redirect "ONLY" the root URL
This example only redirects a root request (example.com) while allowing directly requested subdirectories like example.com/subdir to be accessed.
RewriteEngine on RewriteCond %{HTTP_HOST} example\.com [NC] RewriteCond %{REQUEST_URI} ^/$ RewriteRule ^(.*)$ /blog/$1 [L]
Redirecting in WordPress
See the official WordPress page for instructions on how to configure this withing your WordPress website.