0

I've modified my .htaccess file to allow access to html files without having to include the extension on the end, for example:

www.mysite.com/document

directs to

www.mysite.com/document.html

However, when I want to link to pages within my site using something like <a href="page.html"></a> I still get the .html appearing in the URL.

So am I allowed to exclude the extension and leave a link as <a href="page"></a> so that the extension doesn't appear in the browser? Or is there a better way to do it?

1 Answer 1

2

Yes, make your links match your URLs.

5
  • Surely this bad practice? If you create a link like <a href="page"></a> how does the browser know how to interpret it? For all it knows, it could be an image file.
    – Anime163
    Commented Jul 6, 2012 at 14:38
  • The browser doesn't know that a .html page is a web page, some are .cgi, some are .php, some are .aspx. The browser requests it, then the server sends the correct MIME type back.
    – cjk
    Commented Jul 6, 2012 at 14:45
  • @Anime163 Definitely No. Browser analyse server response headers (Content-Type in particular) as well as actual file content to identify correct format (display/processing method). It is not a surprise to see on the web file with .jpg extension that in fact is .png file (or other way around). If on my site all pages have .do extension -- how browser should treat them (accordingly to your logic)?
    – LazyOne
    Commented Jul 6, 2012 at 14:45
  • Thanks for the responses! So if I go through my whole site removing the extensions on the links to html files, that's an acceptable way to do it?
    – Anime163
    Commented Jul 6, 2012 at 14:47
  • Yes, that's fine.
    – cjk
    Commented Jul 6, 2012 at 15:13

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.