views:

816

answers:

3

I have changed some file names on my web and now I want to make "301 Permanently Moved" redirect from the old files to the new ones.

The problem is that my web is made completelly by static html pages and all 301 redirect tutorials decribe how to do it in PHP, ASP, htaccess etc. I would like to write the redirect directly into the old html files, is this possible? Or do I have to contact my web provider and solve the redirect on the server?

The only thing I know about the server is that it runs on Windows and I have no server knowledge.

EDIT: My web hosting is using Microsoft IIS 7.0, so I assume using the .htaccess is not possible here?

EDIT #2: just now my server admin wrote me that even if I use only static HTML pages, I can still use web.config file to redirect individual html files. This is very nice.

+4  A: 

You cannot alter the HTTP status code with HTML.

But if you’re using an Apache webserver, you could use mod_rewrite or mod_alias to redirect such requests to the new address:

# mod_rewrite
RewriteEngine on
RewriteRule ^old\.html$ /new.html [L,R=301]

# mod_alias
RedirectMatch 301 ^/old\.html$ /new.html


Edit   As you now clarified that you’re using IIS 7, take a look at its <httpRedirect> element for HTTP redirects.

Gumbo
My web hosting is using Microsoft-IIS/7.0, is there any similar way or redirect?
Take a look at this: http://www.iis.net/ConfigReference/system.webServer/httpRedirect
Gumbo
+2  A: 

No, it isn't possible. HTML is not processed by the server, so it cannot set HTTP headers.

You should look at Apache configuration instead (e.g. with .htaccess).

At its simplist you could do:

  Redirect 301 old.html http://example.com/new/
  Redirect 301 other-old.html http://example.com/newer/
David Dorward
You cannot set HTTP header fields, that’s right. But the `http-equiv` in `meta` elements are supposed to be HTTP equivalent. So those informations are supposed to be treated as HTTP header fields.
Gumbo
No, http-equiv was supposed to be read and parsed by HTTP server, not by clients. HTTP servers don't do that, and clients have quite poor support for this. It's a half-dead, half-broken feature which is almost completely removed in HTML5.
porneL
@proneL: Ah yes, you’re right.
Gumbo
+1  A: 

I guess you could use JavaScript and/or meta-refresh (as suggested by Gumbo) to redirect the users from your old pages to the new one. Something like:

<html>
<head>
  <meta http-equiv="refresh" content="0;url=http://YourServer/NewFile.html" />

  <script type="text/javascript">
    location.replace('http://YourServer/NewFile.html');
  </script> 
</head>
<body>
  This page has moved. <a href="http://YourServer/NewFile.html"&gt;Click here for the new location</a>
</body>
</html>
mrMoo
The only reason for having the JS redirect seems to be for people who disable meta refresh, which I don't suppose many do. I used to have this three-level redirect on a site I maintain, but have since dropped the JS redirect. Somebody who hates meta refresh enough to disable it will likely hate JS doing the same.
Stewart