Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Web Server Configuration _ removing .html extension in folders

Posted by: matthewhunt Aug 16 2017, 10:30 PM

I have a site with pages organised into different folders. For example:

http://www.matthewhunt.com/cinema/index.html

I can access this page by typing http://www.matthewhunt.com/cinema/ but http://www.matthewhunt.com/cinema (without the final /) returns a 404 error.

How can I configure to access via http://www.matthewhunt.com/cinema (without the final /)?

Thank you.

Posted by: Christian J Aug 17 2017, 05:56 AM

Normally a URL without a trailing slash indicates a file, not a directory. This can be changed on the server in various ways, details may differ between web hosts.

Personally I'd keep the slashes for directories, it's both simpler and easier to understand.

Posted by: matthewhunt Aug 17 2017, 06:23 AM

QUOTE(Christian J @ Aug 17 2017, 05:56 AM) *

Normally a URL without a trailing slash indicates a file, not a directory. This can be changed on the server in various ways, details may differ between web hosts.


Thanks, Christian. I should have explained that the destination is the index.html file in the directory, not the directory itself. Is it possible to set the URL http://www.matthewhunt.com/cinema (for example) to open the index.html file in the /cinema/ directory?


Posted by: Christian J Aug 17 2017, 07:23 AM

QUOTE(matthewhunt @ Aug 17 2017, 01:23 PM) *

Is it possible to set the URL http://www.matthewhunt.com/cinema (for example) to open the index.html file in the /cinema/ directory?

The IIS server seems to do that by default, according to https://support.microsoft.com/en-us/help/298408/iis-generates-courtesy-redirect-when-folder-without-trailing-slash-is (note that it seems to redirect the URL, not just serve the content of matthewhunt.com/cinema/index.html while retaining the URL matthewhunt.com/cinema).

The Apache server may require .htaccess directives: https://serverfault.com/questions/250161/how-do-i-remove-trailing-slashes-from-a-url-when-using-apaches-default-director

Sometimes web hosts have already implemented various features that may complicate things. Blogging scripts may also use their own features.

But see also http://webtips.dan.info/subdir.html#FinalSlash on why it may be a bad idea.



Posted by: Darin McGrew Aug 18 2017, 12:45 AM

QUOTE(Christian J @ Aug 17 2017, 05:23 AM) *
But see also http://webtips.dan.info/subdir.html#FinalSlash on why it may be a bad idea.
This bears repeating.

The URLs .../cinema/ and .../cinema/index.html are at the same level when it comes to relative links, and they're practically interchangeable.

The URL .../cinema is at a different level when it comes to relative links, and it is not interchangeable with the other two.

Posted by: matthewhunt Aug 19 2017, 11:20 PM

QUOTE(Darin McGrew @ Aug 18 2017, 12:45 AM) *

QUOTE(Christian J @ Aug 17 2017, 05:23 AM) *
But see also http://webtips.dan.info/subdir.html#FinalSlash on why it may be a bad idea.
This bears repeating.

The URLs .../cinema/ and .../cinema/index.html are at the same level when it comes to relative links, and they're practically interchangeable.

The URL .../cinema is at a different level when it comes to relative links, and it is not interchangeable with the other two.


That's very clear. Is it therefore possible to create an HTML file that can be accessed via the URL .../cinema ? (For example, the BBC News site has URLS such as bbcnews.com/uk and bbcnews.com/sport etc that link to files rather than directories.) Or is this done simply with a redirect?

Posted by: Darin McGrew Aug 20 2017, 12:43 AM

QUOTE(matthewhunt @ Aug 19 2017, 09:20 PM) *
Is it therefore possible to create an HTML file that can be accessed via the URL .../cinema ? (For example, the BBC News site has URLS such as bbcnews.com/uk and bbcnews.com/sport etc that link to files rather than directories.) Or is this done simply with a redirect?
One way to do it is content negotiation, as described near the end of https://www.w3.org/Provider/Style/URI

Posted by: Christian J Aug 20 2017, 10:05 AM

QUOTE(Darin McGrew @ Aug 18 2017, 07:45 AM) *

The URLs .../cinema/ and .../cinema/index.html are at the same level when it comes to relative links, and they're practically interchangeable.

The URL .../cinema is at a different level when it comes to relative links, and it is not interchangeable with the other two.

Let's see if I got this right. If the URL .../cinema retrieves the HTML file .../cinema/index.html, then relative links in that file such as

CODE
<a href="foo.html">foo</a>

will not resolve to .../cinema/foo.html, but to .../foo.html --is that correct? So basically you can't use relative URLs in some of your links, but must instead use absolute URLs?

Posted by: Christian J Aug 20 2017, 10:23 AM

Regarding how to actually configure the content negotiation I can't find much in the way of tutorials, but here's one at least:
http://www.websiteoptimization.com/speed/tweak/rewrite/


Posted by: Darin McGrew Aug 20 2017, 11:54 AM

QUOTE(Christian J @ Aug 20 2017, 08:05 AM) *

QUOTE(Darin McGrew @ Aug 18 2017, 07:45 AM) *

The URLs .../cinema/ and .../cinema/index.html are at the same level when it comes to relative links, and they're practically interchangeable.

The URL .../cinema is at a different level when it comes to relative links, and it is not interchangeable with the other two.
Let's see if I got this right. If the URL .../cinema retrieves the HTML file .../cinema/index.html, then relative links in that file such as

CODE
<a href="foo.html">foo</a>
will not resolve to .../cinema/foo.html, but to .../foo.html --is that correct? So basically you can't use relative URLs in some of your links, but must instead use absolute URLs?
Pretty much.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)