Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Yes, make your links match your URLs.

share|improve this answer
    
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 Jul 6 '12 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 Jul 6 '12 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 Jul 6 '12 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 Jul 6 '12 at 14:47
    
Yes, that's fine. –  cjk Jul 6 '12 at 15:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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