I have a subdomain


I would like to redirect it to subdirectory as


But not admin(/wp-admin). Admin area should be as it is


currently I have this in my htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]

    RewriteCond %{HTTP:X-Forwarded-Host}i ^example\.com 
    RewriteCond %{HTTP_HOST} ^blog\.example\.com$  
    RewriteRule ^/?(.*)$ https://www.example.com/blog/$1 [L,R=301,NC]

    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{HTTPS} off
    RewriteRule ^/?(.*)$ https://www.example.com/blog/$1 [L,R=301,NC]

and my site URL and WordPress URL is:

WordPress Address (URL)   = /blog 
Site Address (URL)        = https://www.example.com/blog

but this setup redirects every URLs in my website and creating many issues in the backend.

What is the best ways to do this?

  • That won't be easy. You have a lot of files in other folders such as wp-includes that are loaded both in admin and front end.
    – Johansson
    Apr 2, 2017 at 16:35

2 Answers 2


Use below rule,

RewriteEngine On

# excluding www
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{HTTP_HOST} ^blog

# excluding wp-admin
RewriteCond %{REQUEST_URI} !^wp-admin
RewriteRule ^ https://www.example.com/%1
  • 1
    Hey, Abhishek Gurjar nice code. Your answer is off to a good start. Please consider explaining how and why this code solves the problem so others can learn from it. Check the guide to answers for further advice. Sep 2, 2019 at 20:51

Have you tried the following?

        <meta http-equiv="refresh" content="0; url=https://www.example.com/blog" />

This would be your index.php file, and you would place it in http://blog.example.com

Note The 0 in the refresh statement is the number of seconds your page waits before redirecting to a new site, and 0 means redirect immediately.

Note 2 You can make a new theme, that only contains this index.php file above (and the style.css file for theme definition), and switch to this theme, and you will be set. Alternatively, update your existing theme, and add the meta tag above to your header. Either way should work.

  • Thank you @Greeso. It is working. But the includes( js and css ) are still loading from subdomain(blog.example.com). so the page seemed to be broken. Also when we try directly "example.com/blog" this URL it is redirecting infinitely. Apr 3, 2017 at 10:59
  • First, can you go directly to example.com/blog ? If this does not work, then you have a problem. If it works, then try to create a new theme, containing only index.php and style.css , and you index.php would only contain the contenct in the answer above (so nothing is loaded other than this file). See how this works.
    – Greeso
    Apr 3, 2017 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.