: How to force a 302 redirect to index.html when hosting on S3? I've found that the following two URLs will show the same content: http://example.com/blog/ http://example.com/blog/index.html In the
I've found that the following two URLs will show the same content:
example.com/blog/ http://example.com/blog/index.html
In the case of the first URL, it appears to pick up the index.html from the blog pseudo-folder. I guess this is because I have index.html configured as my index document.
However, the browser is not redirected. This means I end up with two different URLs being hit for the same content. From the point of view of analytics and other things this is a pain.
Can I make S3 redirect with a 301 to index.html? Or the other way around?
More posts by @Shakeerah822
2 Comments
Sorted by latest first Latest Oldest Best
Firstly, make sure you are only linking to one version of the URL, whether it is /blog/ or /blog/index.html (I'd prefer the former since it's shorter and simpler).
The best solution with regards to SEO would be to use a canonical tag. Put this inside the <head> tag:
<link rel="canonical" href="http://yoursite.com/blog/">
That means that when search engines see both URLs they are treated the same, and ensures visitors coming from a search engine will hit /blog/ and not /blog/index.html.
If you have links from other sites you may not be able to control where the visitors land, so for analytics purposes it's probably still worth redirecting the user.
I don't know if you have any kind of server-side rules in your situation given that it's a static site, but if you can use .htaccess you should do something like this:
Redirect 301 /blog/index.html /blog/
Finally, if all else fails then redirecting the user with JavaScript is fine:
<script>
if (window.location.href.indexOf('index.html') != -1)
window.location.href = '/blog/';
</script>
place in your /blog/index.html on the top, before opening < head>
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location:http://www.example.com/index.html");
?>
so you get the only one url: with index.html on the end - all tries to come into /blog/ will be redirected to /blog/index.html
On hosting, which doesn't support PHP, use a Javascript:
<script type="text/javascript">
<!--
window.location = "http://www.example.com/blog/index.html";
//–>
</script>
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.