Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

301 Permanent Redirect...

Status
Not open for further replies.

Halcrow

Programmer
Aug 24, 2004
76
GB
I want to set this up using a .htaccess file on the server, but I don't know how to...what should I do?

Thanks
Calum
 

Maybe the forum for your server-side software would be a more appropriate place to ask this question?

Hope this helps,
Dan
 
Sorry to be a bit think, but I don't even know which forum to post this on! Any ideas???

Thanks
Calum
 

Given that you've not told us what server software you're using, don't you think that it would be quite tricky for us to tell you this?

Come on - use some common sense!

Dan
 
Let me explain my problem as well as I possibly can:

I was asked to redirect a site to its new location on the web. The previous host was a free one that doesn't support .php, SSI or anything other than html and jpegs. I had to set up a redirect to the new, nicer, server. I did this using a meta command in the head, like so:

Code:
<meta HTTP-EQUIV="refresh" CONTENT="0;URL=http://www.test1.com/">

Then this guy comes along and says to me: "no no no no no no, thats not the way to do it - you should modify a .htaccess file. Far better solution..." I looked it up but really had no clue as to what he was talking about. So I thought I'd post it on the forum.

Thats all I can say, I know no more!

Hope you can understand what I'm trying to do here and help, even a little.

Note: the meta tag does actually work anyway, so I don't know what all the fuss is about!
 
From this description it looks like Apache web server. Try Forum65.

AFAIK .htaccess directive is more powerful because it can handle relative URI's. For example, if someone comes at oldsite.com/blah/foo.htm, it will be redirected to newsite.com/blah/foo.htm. Basically it means no dead/broken links.
 
.htaccess files will work on servers running Apache.
If you are using an IIS server then you will need to do this a different way.

Your friend was partially correct. A Meta refresh is not the best way to do it.

One "better" way to do it would be to use whatever server side language that you have available (be it PHP, ASP or ColdFusion) to trigger an http redirect.

Using PHP you could do this like this:

Code:
<? //301 redirect from this page to Page B
header("HTTP/1.1 301 Moved Permanently");
header("Location: [URL unfurl="true"]http://www.mydomain.com/B.php");[/URL]
header("Connection: close");
?>

Put that code on your page.. with NO other output. Else the header() command won't work.
That is a search engine friendly way to do the redirect.

Now, you can do the same thing with an .ht access file.
An .htaccess file sits on your server and simply contains some text commands that the server will execute when getting a request for something in the directory that the file is in. You can use it to perform many functions, from password protection and custom error pages to creating anti-leach scripts etc.

It's a bit more complex and I don't really know enough to feel I can "teach" you how to do it. I just did a quick google though and came up with some results that might be of help.

- Web design and ranting
- Day of Defeat gaming community
"I'm making time
 
Bear in mind that, if the host you're redirecting from "doesn't support .php, SSI or anything other than html and jpegs" they quite likely won't support .htaccess files either. No harm in trying though.

If you have to fall back on writing redirect pages on your old server, here's one that I use (copied from an article somewhere - I'd credit them if I could remember!)
Code:
<HTML>
<HEAD>
<SCRIPT language="JavaScript1.1">
<!--
location.replace("[URL unfurl="true"]http://www.example.com");[/URL]
//-->
</SCRIPT>
<NOSCRIPT>
<META http-equiv="Refresh" content="0; URL=http://www.example.com">
<META NAME="ROBOTS" CONTENT="NOINDEX">
</NOSCRIPT>
</HEAD>
<BODY>
This page has moved to a <A href="[URL unfurl="true"]http://www.example.com">new[/URL] location</A>.
</BODY>
</HTML>

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Thankyou everyone for your posts - I now have quite a few different ways to try out now. I actually got the .htaccess file method working on another site last night, but so far haven't tested on my "poor" server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top