301 Redirecting directly to an HTML file

I changed some file names on my website and now I want to do the “301 Permanently Moved” redirect from old files to new ones.

The problem is that my website is made completely static by html pages and all 301 redirect tutorials describe how to do this in PHP, ASP, htaccess, etc. I would like to write a redirect directly to the old html files, is this possible? Or do I need to contact my web provider and solve the server redirect problem?

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

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

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

+3
source share
3 answers

You cannot change the HTTP status code using HTML.

But if you use the Apache web server, you can use mod_rewrite or mod_alias to redirect such requests to a new address:

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

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

Change . As you now find out that you are using IIS 7, look at the element <httpRedirect>for HTTP redirection .

+4
source

, . HTML , HTTP-.

Apache (, .htaccess).

:

  Redirect 301 old.html http://example.com/new/
  Redirect 301 other-old.html http://example.com/newer/
+3

I think you could use JavaScript and / or a meta update (as suggested by Gumbo) to redirect users from old pages to new. Sort of:

<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">Click here for the new location</a>
</body>
</html>
+2
source

Source: https://habr.com/ru/post/1709514/


All Articles