tags:

views:

27

answers:

3

Hey,

This one is kind of easy. How could I redirect people going to:

http://site.com/blog/

To this:

http://site.com/blog/somespecificurl/

I only have one post at the moment and want it to just redirect to post using .htaccess.

Thanks!

A: 

What you're looking for is called URL Rewriting. Here's a tutorial on how to do it:

http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html

Although I'm a .NET guy, and usually do this using the ASP.NET routing engine, I think this will do what you need it to:

RewriteRule ^blog(/)?$ /blog/somespecificurl/

Chris Koenig
This doesn't seem to do the trick. I'm going to keep trying. RewriteRule ^guide(/)?$ /guide/college-student-laptop-guide-2010/
Daniel O'Connor
Take a look at my answer, hopefully it will fix the problem.
AriX
A: 

If don't have access to the server config, and just want to do it in HTML, you can do it this way:

(in the head of http://site.com/blog/index.html)

<meta HTTP-EQUIV="REFRESH" content="0;url=http://site.com/blog/somespecificurl/"&gt;

The 0 is the number of seconds to wait to redirect.

cactusbin
How could I do it (302 redirect) in the .htaccess file? Thanks
Daniel O'Connor
Oh, I apologize.AriX answered this correctly:RewriteRule ^blog(/)?$ /blog/newarticle.html [R]
cactusbin
+1  A: 

As long as you have mod_rewrite enabled in your Apache configuration, you can just make a .htaccess file with these contents:

RewriteEngine on
RewriteRule ^blog(/)?$ /blog/newarticle.html [R]

The RewriteEngine line is important, because it tells Apache to actually pay attention to RewriteRule commands. If RewriteEngine on is specified by default, this is unnecessary, but in many cases, it is not specified by default. The [R] means to force the URL rewrite as a new HTTP request, causing an actual full-fledged redirect (this is unnecessary, it depends on what you're looking for).

Alternatively, you could use the HTTP meta refresh, which is simpler but requires loading the page before the redirection even happens, or you could use PHP redirects if you have PHP enabled on the server. If so, try this in /blog/index.php:

<?php
header('Location: /blog/newarticle.html');
?>
AriX
Thanks, but I can't seem to get this to work. RewriteRule ^guide(/)?$ /guide/college-student-laptop-guide-2010/ [R]
Daniel O'Connor
Even with the RewriteEngine on? Also, did you try the PHP based solution? It's a little bit simpler.
AriX