How to redirect root directory ("/")

How to redirect root directory ("/")

Posted by: vanatta
Posted on: 2006-05-10 13:55:00


Does anyone know if it's possible to redirect a root directory via the control panel?
ex.

http://sub.mydomain.com/ ->
http://sub.mydomain.com/blog

I get errors in the control panel when I attempt to do this (it tells me that it can't redirect a directory within the same domain)

Also, when I tried to "re-map" the directory, the application I installed under /blog didn't work anymore (WordPress).

Basically, my objective was to create a WordPress blog in /blog without using up the root directory of my subdomain. However, I also wanted the subdomain to point to my blog until I determine the application that I'll be installing at the root directory.

Hope someone can help!
-V

Re: How to redirect root directory ("/")

Posted by: vanatta
Posted on: 2006-05-10 14:09:00


Well, in case someone else has run into this issue..
My work-around was to put an index.html page under my root directory.
Then I just added HTML content with a redirect tag:


<html>
<head>
<title>My Title</title>
<META HTTP-EQUIV="Refresh"
CONTENT="0; URL=blog/index.php">
</head>
<body>
</body>
</html>


Re: How to redirect root directory ("/")

Posted by: Raz2133
Posted on: 2006-05-10 16:30:00

In reply to:

My work-around was to put an index.html page under my root directory.


Another option would have been to create a .htaccess file in your root to redirect the request.

Something like...

redirect 301 /index.html http://www.mydomain.com/blog/

or...

DirectoryIndex /blog/index.html

Mark

Re: How to redirect root directory ("/")

Posted by: JKing
Posted on: 2006-05-10 22:23:00

Using a "Refresh" directive from an HTML document is evil: it makes going back difficult, and a robot would have a hard time knowing that the document is intended as a redirection.

Raz' suggestion is good, though I would use a 307 status code for the redirect, since it's pretty clear from our above posting that it's a temporary measure.

I'm not sure exactly what action Apache would take with the DirectoryIndex directive given such a value, though.

(Aside: The 302 status code is more common in these kinds of circumstances, but I believe 307 is more proper in this particular case. According to HTTP/1.1, the only difference in semantics between 302 and 307 is that 307 redirections are expected to be handled with the same request method as the original request, whereas 302 is ambiguous. Me being the stickler I am, though, have come to the conclusion that 302 should be used in cases where a document will -always- be located somewhere other than the original request, but not always the same place (eg. /news/ may redirect to /news/jan/ one month and /news/feb/ the next); and 307 is used in such cases where a document is simply elsewhere for the time being, but will be returning to its original location (as seems to be the case here). Of course, this conclusion is based solely on the advisory names of the statuses ("Found" and "Temporary Redirect" respectively) and otherwise has very little basis in reality. :) )Edited by JKing on 05/10/06 10:48 PM (server time).

Re: How to redirect root directory ("/")

Posted by: Raz2133
Posted on: 2006-05-10 23:46:00

In reply to:

though I would use a 307 status code for the redirect, since it's pretty clear from our above posting that it's a temporary measure.


Good call. On reflection a 302 or 307 code to signify a temporary move would definitely suit the circumstances better.

In reply to:

I'm not sure exactly what action Apache would take with the DirectoryIndex directive given such a value, though.


I wasn't completely sure this would work either, but I just tried it and it seems to have the expected result (at least it does on my particular Apache install).

Mark

Re: How to redirect root directory ("/")

Posted by: vanatta
Posted on: 2006-05-11 00:11:00


I'm now using the .htaccess redirect.

Since there's no client-side content that goes with the redirect method, it seems to be working faster as well.

Thanks for your help and suggestions!

Re: How to redirect root directory ("/")

Posted by: Scope
Posted on: 2006-05-11 02:18:00

with wordpress, you can just set up a front page in your root, create an index.php and add these 4 lines...


<?php
define('WP_USE_THEMES', true);
require('./blog/wp-blog-header.php');
?>


and thats it, your blogs main page gets pumped into that page on the root.

Search for "static front page" onwordpress.org for more info.


Tags: root directoryredirectmydomaincontrol panelhttp