Redirect your root directory to a subdirectory

 

Overview

You can redirect requests for your primary website URL (example.com) to a subdirectory (example.com/blog) — either all requests or only the root URL — by adding code to your .htaccess file.

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):

How do I redirect requests to a subdirectory?

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.

How do I 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.

  1. Log in to your server via FTP.
  2. Upload (or create) a text file named .htaccess (with no extension).
  3. Place the file in the website directory.
  4. 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]

How do I 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]

How do I redirect in WordPress?

See the official WordPress page for instructions on how to configure this within your WordPress website.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?