Question

I have static site (html + css) generated by nanoc. It works under Apache.

I want use pretty url instead of .html suffix at the end. Like this:

  • http://domain.ru
  • http://domain.ru/page/page1/
  • http://domain.ru/page/page2/

instead of

  • http://domain.ru/index.html
  • http://domain.ru/page/page1.html
  • http://domain.ru/page/page2.html

So, the 1st way is to create the separate folders with names page1 and page2 and place inside index.html files with corresponding content. When client does request:

http://domain.ru/page/page1/ is loaded file page1/index.html

The 2nd way is to have such files structure:

page (folder)
- page1.html (file)
- page2.html (file)

and create rule for .htaccess file in root of the site:

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.+)/$ /$1.html

So, the question is which way is better ? May be there are some additional costs of using rewrite rules or pitfalls? May be there are some good practices for this questions for static generated sites.

PS: In any way i use .htaccess file: i need switch on utf-8 encoding, enable 404 error handling , disallow browse folders

Thanks and sorry for bad english :)

Was it helpful?

Solution

I prefer to use index.html in directories, because it is server -independent. I don’t think there’s a good reason not to do it that way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top