Redirect to subdir

Hi folks–

I’m sure this has been answered here before: in fact, I’ve found a couple answers in the forum archives, so I’m unsure of the best way to do this and I’d like some clarification:

When someone navigates to mydhdomain.tld/ I would like them to be redirected to mydhdomain.tld/blog/ . What is the Best Way to do this?

I’ve seen suggestions of using .htaccess to do a redirect, but also suggestions that that won’t work (I don’t want recursive mydhdomain.tld/blog/blog/blog/…); is there a special index.* that I can put in mydhdomain.tld/ to accomplish this?

…/blog/ is where my wordpress installation is. I don’t want to set up wordpress so it displays at mydhdomain.tld/ --I’m imagining I might want some other front page eventually, or something; I don’t want mangled internal links in my blog if I change its display location and permalink structure at some point in the future. Rather, I just want anyone arriving at mydhdomain.tld/ to get dropped at mydhdomain.tld/blog , set up in such a way that I can easily undo it later if I want to put up some mydhdomain.tld/index.html that welcomes folks to the site and links to my blog, or something.

Thanks in advance!

I think the best solution for what you describes is to just set up a “permanent redirect” for now, that takes anyone arriving at http//yourdomain.tld and “automagically” forwards them to http://yourdomain.tld/blog/. This should not result in any "recursive’ mangling of the url. :wink:

Put the following line in an text file named “.htaccess”, and place it in the /home/username/yourdomain.tld (http://yourdomain.tld) directory:

redirectpermanent / http://yourdomain.tld/blog/
This won’t mess up the search engines, allows you to remove it latter and add additional/other content at http:/yourdomain.tld in the future, and allows your blog to operate from http://yourdomain.tld/blog with all it’s oroginal structure intact (permalinks, etc.).

If you want to "undo it later, all you will have to do is remove that line from the .htaccess file, or removed the .htaccess file altogether.


…I should add that, obviously, navigating directly to mhdhdomain.tld/blog/ should of course work correctly.

rlparker, thanks for your reply–I haven’t had the chance to try your suggestion out yet, but I will tomorrow.


should there be a space between ‘redirect’ and ‘permanent’, or is it all one command?

That will still work fine, as will any other valid urls within your domain; all that the redirect does is to redirect that singlehttp://yourdomain.tld/” url to “”. :wink:


Actually, any of the following will work just fine:

redirect 301 / http://yourdomain.tld/blog/
redirect permanent /
redirectpermanent /

Note that there is a space between the first “/” and the following “http://” :wink:



Redirect permanent / http://mydhdomain.tld/blog/

didn’t work. When I point my browser to “http://mydhdomain.tld”, I get redirected to “http://mydhdomain.tld/blogblogblogblogblogblog…”, as I feared might happen–the redirect gets evaluated recursively. I thought I saw a post indicating that this would happen, but now I can’t find it.

Any other suggestions?


Yikes! Sorry for the “bum steer”… I think I see the problem now …

Try this:

Redirect permanent / http://mydhdomain.tld/blog/index.php

…and let me know if that solves the problem!

Edited: - No it won’t solve the problem (i got a chance to test it on a similar circumstance)… see my Next post.



I wasn’t able to find a “clean” way to do this via a redirect without munging up the existing WordPress directory’s .htaccess file and rewrite rules. I *don’t * think that is what you want to do, as it would be a bit of a mess to change it back if you decided to use your http://yourdomain.tld/ page for something else at a latter time and needed your blog to then be “intact” at http://yourdomain.tld/.

This experience did jog my memory though; remembering having set up a client like this once before and a trip to the WP codex reminded me how I did what are are trying to do.

With slight modifications (since you already have a functioning blog at http://yourdomain.tld/blog/), you can use the process detailed in the WP Codex article on “Giving WordPress Its Own Directory” to leave you blog functioning at it’s present location, but have it reached from http://yourdomain.tld/.

Essentially, you are making a couple of changes in the WordPress backend (describing the new “WordPRess root”), and putting copies of WP’s index.php and .htaccess in the “root” directory of your site. You need to then edit that “root” copy of index.php,to correct the path for the header include.

Basically, you are following the instructions in the article, except you do not need to do steps 1,3, and 6 (your files are already there.)

This ought to do what you want, and is pretty easy to reverse if you ever want to change your site structure back - Just “reverse” the process in the WP backend and delete the index.php and .htaccess in your “root” directory.

You may need to manage some content redirects if the new permalinks create a problem for you with inbound links - but there are WP plugins to help with that, if need be.

Again, I apologize for the incorrect direction I gave re the redirect permanent; this process, however, does work (I’ve have done it) and this is how WordPress says it should be done. :wink:


Nope. Predictably, that results in http://mydhdomain.tld/blog/index.phpblog/index.phpblog/index.phpblog/index.phpblog/index.php

However, I found the thread I mentioned: it’s
and it contains instructions to make an index.php which does the trick by sending a 302 (temporary redirect) header. I’ll reproduce it here for posterity:

make …/mydhdomain.tld/index.php with the following contents:

<?php header('Location: http://www.mydhdomain.tld/blog') ?>

It can also be done with a meta html tag, but my copy of Web Design in a Nutshell says the W3C frowns upon this use. Didn’t say the right way to do it, exactly, though…

I’d still be interested in hearing if there’s a commonly accepted Best way to do this, if anybody knows.

Thanks for sharing your find on that! I was so “stuck” on thinking of an .htaccess based solution I didn’t even think of using PHP.

One thing you might consider if you use this approach, is that by modifying that index.php slightly you can still have a “301” status returned, instead of the “302” like so:

<?php header("HTTP/1.0 301"); header("Location: http://yourdomain.tld/blog/"); /* Redirect browser */ /* Make sure that code below does not get executed when we redirect. */ exit; ?>

I agree that using a meta-refresh is not the best idea, and that can cause you grief with search engines; this way is better (or the “WordPress recommended” method I mentioned in my other post).