views:

299

answers:

4

If you go to www.codinghorror.com, it is automatically redirected to www.codinghorror.com/blog

How does one re-direct to the "/blog/"?

I'm using Dreamhost Shared Hosting, so my options of configuring the server are limited.

+2  A: 

Assuming Apache with mod_rewrite and context permissions allowing its use, you put this in virtual host configuration or a .htaccess:

RewriteEngine on
RewriteRule ^$ /blog/
chaos
+2  A: 

One way is by sending a 'Location' header to the client. Here's a PHP example:

<?php

header('Location: http://www.codinghorror.com/blog');

?>
yjerem
+3  A: 

Another option is using Apache's mod_alias to do a permanent redirect (in either .htaccess or httpd.conf):

RedirectPermanent / /blog

There are probably as many ways as there are servers and programming language (probably even more then that). If you tell us what specific technology you use it can probably help to give you a more specific answer.

Guss
+5  A: 

This would be a good opportunity to teach yourself about HTTP status codes. Read the status code definitions section of the HTTP 1.1 spec; section 10.3, "Redirection 3xx," covers the status codes pertinent to your question. Knowing the HTTP 3xx codes means that you can send a response that has exactly the semantics that you intend. For example, if you intend for the redirect to always occur, you could use HTTP 301, "Moved Permanently." In theory, a client could use the HTTP 301 response as a signal to store the new URL value in place of the old one.

Your configuration options at Dreamhost are not as limited as you would think, because you can specify many Apache web server configuration directives in a hidden .htaccess file. This file should be placed in a web document directory; using your example, you would place it in the root web document directory, /home/midas/codinghorror/, though .htaccess files can be placed in any directory served by Apache. (Remember to include the leading dot in the filename.) Its contents would be either the mod_alias example or the mod_rewrite example already mentioned.

Note that mod_alias's RedirectPermanent directive will send an HTTP 301 status code for you. If you wanted to use mod_rewrite to do this, you could specify the status code:

RewriteEngine on
RewriteRule ^$ /blog/ [R=301]

If you use [R] without a code, then HTTP 302 ("Moved Temporarily") is used.

Since PHP is also available to you, that's also an option, though it's possible that the above options using .htaccess are faster. You would place a file called index.php in /home/midas/codinghorror/ and use the code given by Jeremy Ruten above. Again, you can specify a status code in the third argument to header():

<?php
header('Location: http://www.codinghorror.com/blog', TRUE, 301);
?>

Otherwise, using PHP's header() function with 'Location' defaults to sending an HTTP 302 status response.

cobra libre