-4

What do you guys think is the best way to link to other website pages of a website, in order to remove the .html extension visible in website URL?

Assume I have the following pages:

  • index.html
  • page1.html
  • page2.html
  • pagex.html

What is the best way to link to these pages?

  • <a href="page1.html">page1</a>
  • creating subfolders named "page1", "page2", and so on, with individual "index.html" files, and referral in the form of:

    <a href="/page1">page1</a>    
    
  • Use <a href="page1">page1</a> and set .htaccess to MultiViews

John
  • 1
  • 2
  • 1
    "What do you guys think" sounds a lot like an opinion-based question rather than one with a definitive answer. – O. R. Mapper Oct 29 '15 at 10:31
  • What's wrong with a dead simple `src="page1.html"`?! It works, it doesn't need anything extra, it's standard compliant, it's fine. Unless you can tell us why you possibly *wouldn't* want this and what else you'd want, go with it. – deceze Oct 29 '15 at 10:34
  • I agree with you that there is no definitive answer to tis question, as it might be a preference based one. With regard to your suggestion, @deceze, how does 'src="page1.html"' refer to linking to other webpages? I am asking this question because I do not think 'websitename/page1.html' looks really need. 'websitename/page1' looks better. – John Oct 29 '15 at 10:40
  • I meant `href="page1.html"`, sorry. – deceze Oct 29 '15 at 10:48
  • So your actual question is *how to best have the URL appear without the .html extension?* – deceze Oct 29 '15 at 10:49
  • You are right, @deceze. Reframed question to: Best way to link to pages, in order to let URL appear without the .html extension? Thank you – John Oct 29 '15 at 10:57

2 Answers2

0

The best way is to divide your page up in sections you have an admin section? make a folder nameed admin and make your path as so admin/index.html so just every section on your page should have a folder and files inside that folder but i do not believe there is any guidelines to this so it is just my opionion

Anoxy
  • 873
  • 7
  • 17
0

In your .htaccess file, use a rewrite directive:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) $1.html

This rule says: if the requested file does not exist, (internally) append an .html to it. That means the URL will show /page1, which will fit the RewriteCond, and internally the request will be treated as if /page1.html had been requested. That's the most straight forward way to map arbitrary URLs of your choice to arbitrary files on disk. Your links would then use the URL href="page1".

Also see Reference: mod_rewrite, URL rewriting and "pretty links" explained

Community
  • 1
  • 1
deceze
  • 510,633
  • 85
  • 743
  • 889
  • It sounds good. Are there any reasons to assume Googlebot will have any trouble in indexing the website? I mean, `href="page1` will be appended by `.html` by the server. Will the indexing by Google do the same? Thank you. – John Oct 29 '15 at 11:37
  • It doesn't matter what the server does or doesn't do. When you visit ***the URL*** `/page1`, you see your site. Done. It looks exactly the same to your browser as it does to Google. – deceze Oct 29 '15 at 11:40