301 Redirect directly in HTML file - html

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.

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.

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. Click here for the new location
</body>
</html>

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/

Redirecting individual pages in IIS is a simple affair and done in your web.config file.
<location path="products.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://yourserver/products" httpResponseStatus="Permanent" />
</system.webServer>
</location>

Related

Wordpress website redirects to "index.html" which doesn't exisit

My Wordpress website, www.the-family-historian.net, goes directly to /index.html, which doesn't exist. I have it set in the Wordpress backend so that the landing page is the posts (blog) and not a static page, but this "index.html" seems to be blocking it. Thanks for any help!
Try setting the following at the top of the .htaccess file:
DirectoryIndex index.php
This should force any request to go to index.php first and ignore index.html, not a 301 redirect though.
Using an FTP program, or possibly a web based file manager, view the files that make up your website. Find an option to view "system / hidden files" in order to view the .htaccess file. I suspect you will find a rewrite rule in it pointing to index.html Simply change that to index.php and all should be good.

Create Download Link Properly

I am new at web developing, I was trying to create download link for a file. This is the code:
<a href="http://symphonyrecords.ir/ARTISTS/Sasan-Khan-Namoondi/SasanKhan-Namoondi[320].mp3" target="_blank" download="SasanKhan-Namoondi[320]">
<button class="downBtn1">Download</button></a>
But when I click the link the file starts downloading inside the browsers not in IDM. (I have tested other links from websites and there was no problem). Should I do something in the meta tag or something ?
After one day research and strangling i found the answer ... I just add onclick method and put the file link with www inside windows.open like this :
<a onclick="window.open ('http://www.symphonyrecords.ir/ARTISTS/Sasan-Khan-Namoondi/SasanKhan-Namoondi[320].mp3', ''); return false" href="javascript:void(0);" download>
<button class="downBtn1">Download</button></a>
This is not the best answer but it will do the job
What is the server side language you have?
You need to set the below header from the server response,
Content-Disposition: attachment; filename=SasanKhan-Namoondi[320].mp3;
On the other hand, you can do the same at web server level. For an instance, if you use Apache, you can do this with .htaccess file
<IfModule mod_headers.c>
<FilesMatch "\.(mp3|MP3)$">
ForceType audio/mpeg
Header set Content-Disposition "attachment"
Allow from all
</FilesMatch>
</IfModule>
Also, you have to enable headers module to make this works,
Make sure the below is checked
Apache -> Apache Modules -> headers_module
Download
You can try this link:-How can I create download link in html?
Your code looks totally fine so it's certainly something with your browser or the download manager.
Have you tried it with another download manager?
Maybe you can give this one a try.

Code to redirect atom feed

Is it possible to define a redirect for an atom feed? If so, how does one do this? I attempted to simply replace my old atom.xml file with an 301 redirect HTML file, like so:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta rel="canonical" http-equiv="refresh" content="0;url=http://io.carlboettiger.info/2014/atom.xml" />
<link rel="canonical" href="http://io.carlboettiger.info/2014/atom.xml"/>
</head>
</html>
and saved this as atom.xml, but (perhaps because of the misleading xml extension?) this doesn't seem to redirect either in the browser or any existing feed reader.
For the RSS format, it looks like the rssboard suggests that an html redirect or an XML-based redirect like so
<redirect>
<newLocation>
http://weblog.infoworld.com/udell/rss.xml
</newLocation>
</redirect>
should do it, but I cannot find any such advice for the atom format. So, how does one define redirects for atom files? (Note: I'm not looking for a hack using .htaccess rewrite rules, since the site is deployed via Github's gh-pages and I don't have the option of custom .htaccess rules anyhow)
Is it possible to define a redirect for an atom feed?
Yes, but only through HTTP redirection. In general, this is the best way to redirect a resource on the web.
the site is deployed via Github's gh-pages
As 301 redirect for site hosted at github? indicates, there's no way to specify HTTP redirection for a GH-pages-hosted site.
The Atom spec assumes that you have control over the server, and doesn't define any additional redirection mechanism.
Unfortunately I don't know of any standard (be it de-facto) to achieve this. As far as I know, the only way to do so is to find ways to do it at the HTTP level, which you don't control when using Github pages.
Both ways you're trying are documented, but I don't know of any reader which actually implements them. At Superfeedr, we have also seen redirects using the iTunes pattern: <itunes:new-feed-url>.
We've been able to do it using services like cloudflare which will act as proxies and allow you to setup rules for specific pages or addresses.

Load same page with different URLs?

I want to create a single page such as this:
http://www.mywebsite.com/special/index.html
But anything in the /special/ folder should be able to load the index.html page. For example, if you go to
http://www.mywebsite.com/special/another-page.html
It should still load the index page but not change the URL in the browser or to search engines. Basically, you should be able to go to any page in the /special/ folder, keep the URL the same as you enter, but always load the index.html page. Any ideas?
A 404 or 301 redirect wouldn't work because that changes the URL in the browser and to search engines...
Thanks in advance!
A 404 redirect would not help, but a custom 404 handler would:
error404.php:
<?php
include('path/to/special/index.html');
?>
Assuming .html is a static or PHP page. If it is something else, youse the equivalent construct of that environment.
Using apache mapping it should be possible. I don't how to exactly do that but this doc http://httpd.apache.org/docs/2.0/urlmapping.html probably has the answer.
It is possible to use patterns to map URL to filesystem locations.
I think (untested) something like this would work in an .htaccess file in the special directory if you have the ability to use rewrite rules:
RewriteRule ^.*$ index.html
You would have to symlink index.html in the special directory to the real index.html.
The ^.*$ just means (beginning of line)(any amount of anything)(end of line) - basically a wildcard; there might be a better way of writing it.

How do I tell Apache to serve files with no extension as text/html?

Consider a webpage, located at http://www.example.com/mypage.html
Unfortunately, someone wrongly advertises that the page's address is http://www.example.com/mypage - people visiting that URL are seeing a 404.
How can I configure Apache so visitors to mypage end up at mypage.html ?
I tried "ln -s mypage.html mypage", but the raw HTML was displayed (I guess because the file was served as text/plain)
I guess I need something in a .htaccess page but I can't work out what...
I would rather redirect the user in stead of going the mime-type way:
Redirect 301 /mypage http://www.example.com/mypage.html