我有nanoc生成的静态站点(html css) . 它适用于Apache .
我想在最后使用漂亮的url而不是.html后缀 . 像这样:
-
http://domain.ru
-
http://domain.ru/page/page1/
-
http://domain.ru/page/page2/
代替
-
http://domain.ru/index.html
-
http://domain.ru/page/page1.html
-
http://domain.ru/page/page2.html
因此,第一种方法是创建名称为page1和page2的单独文件夹,并将index.html文件放在相应的内容中 . 当客户请求时:
http://domain.ru/page/page1/已加载文件page1 / index.html
第二种方式是拥有这样的文件结构:
页面(文件夹)
- page1.html(文件)
- page2.html(文件)
并在站点的根目录中创建.htaccess文件的规则:
RewriteEngine on
RewriteCond%!-d
RewriteCond%! - f
RewriteRule ^( . )/ $ /$1.html
那么,问题是哪种方式更好?使用重写规则或陷阱可能会有一些额外的成本吗?对于静态生成的站点,可能存在一些针对此问题的良好实践 .
PS:无论如何我使用.htaccess文件:我需要打开utf-8编码,启用404错误处理,禁止浏览文件夹
谢谢,抱歉英文不好:)
1 回答
我更喜欢在目录中使用
index.html
,因为它与服务器无关 . 我不认为不这样做是有充分理由的 .