Best way to do a redirect?

howie_23

Supreme [H]ardness
Joined
Mar 14, 2006
Messages
5,426
I have a wordpress install installed in the folder site (<domain name>/site/). I would like to have people type <domain name> and have it redirect to <domainname>/site/. I know there are a lot of different options to do this, what is the best way to do it?

This is installed on an apache server w/ php. Thanks!
 
I just do

Code:
HTTP-EQUIV="Refresh"
CONTENT="5; URL=/link_to_different_page/">
 
just an index page in the root of the site

full code for the page:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>House of Representatives</title>
</head>
<META 
     HTTP-EQUIV="Refresh"
     CONTENT="5; URL=/index/">
<body bgcolor="#6e4124">
<br />
<br />
<div align="center"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif" color="#FFFFFF">If your browser does not automatically forward you click <a href="/index/">here</a>.</font></div>
</html>
 
Yuck. Use HTTP for this, not HTML. HTML redirects are a messy, ugly hack. You should only use them if you actually want the user to see a landing page/intro/domain name change info and leave them there for 15s or whatever.

Code:
RedirectMatch permanent ^/$ http://newurl.com/newpath/

Edit: And if .htaccess permissions aren't set up to allow this or mod_alias isn't loaded for whatever reason (they normally would be with shared hosting), use a PHP index file:

Code:
<?php
Header("Location: /newpath");
?>
 
Last edited:
I just do this:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="REFRESH" content="0;url=http://site.com/blog"></HEAD>
<BODY>
</BODY>
</HTML>
 
i remember reading somewhere that search engines don't like HTTP redirects... you should use 301 Redirects instead. With that being said though, sometimes you don't have direct control of the server so HHTP{ redirect is your only choice
 
i remember reading somewhere that search engines don't like HTTP redirects... you should use 301 Redirects instead. With that being said though, sometimes you don't have direct control of the server so HHTP{ redirect is your only choice

This. Use 301 redirects whenever possible.

This either means using an .htaccess file, or if unavailable, the PHP header redirect that keenan mentioned.

Not only do search engines hate them, but HTML redirects are so 1990s :)
 
You can also do a "redirect" in Javascript.
Code:
<script type="text/javascript">
  window.location = "http://www.google.com/"
</script>
 
You can also do a "redirect" in Javascript.
Code:
<script type="text/javascript">
  window.location = "http://www.google.com/"
</script>

<lumberg>ahhh.. I'm going to have to kinda...disagree with that</lumberg>
 
Back
Top