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!
 

Version_3

2[H]4U
Joined
Nov 19, 2007
Messages
4,076
I just do

Code:
HTTP-EQUIV="Refresh"
CONTENT="5; URL=/link_to_different_page/">
 

Version_3

2[H]4U
Joined
Nov 19, 2007
Messages
4,076
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>
 

keenan

2[H]4U
Joined
Aug 5, 2009
Messages
2,695
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:

kumquat

Supreme [H]ardness
Joined
Dec 7, 2005
Messages
5,269
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>
 

maw

Supreme [H]ardness
Joined
Sep 27, 2000
Messages
4,135
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
 
Z

Zinn

Guest
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 :)
 
Joined
Dec 10, 2006
Messages
540
You can also do a "redirect" in Javascript.
Code:
<script type="text/javascript">
  window.location = "http://www.google.com/"
</script>
 

maw

Supreme [H]ardness
Joined
Sep 27, 2000
Messages
4,135
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>
 
Top