3

How do you configure a site so that when someone is on your home page, they are looking at www.example.com, rather than www.example.com/Index.html? I would like it to show the way that Google's homepage does.

Is it possible with a simple HTML site running on shared hosting with FTP access?

2
  • Assuming Apache? (Although, Index.html with a capital I ...?)
    – MrWhite
    Commented Feb 18, 2016 at 15:02
  • @w3dk yes, I believe it is apache based (one.com), lowercase i - yes! Commented Feb 18, 2016 at 15:17

2 Answers 2

1

if running Apache use following rule in htaccess:

RewriteCond %{THE_REQUEST} ^.*/Index\.html
RewriteRule ^(.*)Index.html$ /$1 [R=301,L] 
1
  • 1
    Minor regex tidy: ^.*/Index\.html is the same as /Index\.html (the ^.* prefix is not required). The dot should be escaped in the RewriteRule pattern also.
    – MrWhite
    Commented Feb 18, 2016 at 17:48
1

In addition to Evgeniy's answer which handles the situation when the /index.html URL is inadvertently exposed (and indexed) and needs to be canonicalised, you should also ensure that you always link to the bare URL, ie. / and not /index.html. The end user should never see "index.html" anywhere.

For / (the bare directory) to work (to silently request index.html) you need to ensure that mod_dir is enabled (it is be default) and that the DirectoryIndex is set appropriately (default is index.html). For example:

DirectoryIndex index.html index.php

The DirectoryIndex directive tells Apache which file to serve when a filesystem directory (eg. example.com/ or example.com/directory/, etc.) has been requested. In this case it will look for index.html and if not found will check for index.php, etc. in the respective directory.

To also help the search engines to always index (or at least, return in the SERPs) the correct/canonical URL you can include a rel="canonical" element in the head section of your pages pointing to the correct URL. For example:

<link rel="canonical" href="http://example.com/">

And lastly, setup an external redirect to correct any index.html URLs that have already been indexed. (See Evgeniy's answer.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.