# Add .html extension by default

**URL:** <https://www.ruby-forum.com/t/add-html-extension-by-default/161220>\
**Category:** Rails\
**Created:** [February 24, 2009, 12:17pm UTC](https://www.ruby-forum.com/t/add-html-extension-by-default/161220 "2009-02-24T12:17:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f1d935/32.png) [@gerold](https://www.ruby-forum.com/u/gerold)\
**Post date:** [February 24, 2009, 12:17pm UTC](https://www.ruby-forum.com/t/add-html-extension-by-default/161220/1 "2009-02-24T12:17:07Z")

</div>

Hi all,

i would like to add the .html extension by default to all my  
resources. What is the best way to do that? The reason for this is  
that i need to download the generated sites via wget and i need  
the .html extension for the downloaded files. Also it would be nice if  
the link\_to would automatically generate the links with .html…

Thanks,

Gerold

---

<div class="post-metadata">

**Author:** ![gerold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f1d935/32.png) [@gerold](https://www.ruby-forum.com/u/gerold)\
**Post date:** [February 24, 2009, 12:29pm UTC](https://www.ruby-forum.com/t/add-html-extension-by-default/161220/2 "2009-02-24T12:29:26Z")

</div>

how about a before/after\_save callback? i guess that would work.

---

<div class="post-metadata">

**Author:** ![gerold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f1d935/32.png) [@gerold](https://www.ruby-forum.com/u/gerold)\
**Post date:** [February 24, 2009, 1:00pm UTC](https://www.ruby-forum.com/t/add-html-extension-by-default/161220/3 "2009-02-24T13:00:01Z")

</div>

Maybe i was a little too unspecific with my description. Let me try  
again:

The website has multiple nested pages and i can address them with  
e.g. /pages/first /pages/first/subpage  
Now when i want to wget all of the pages the downloaded files are  
called first and subpage but  
i’d like them to be called first.html and subpage.html so i figured  
the easiest way to do that is to just add  
.html at the end of all pages by default.

So when i add a resource to routes.rb like

resources :pages

i can call /pages/1 and i get the first page but again if i download  
it the file would be called 1 instead of 1.html…  
Also if i use link\_to or url\_for i get the links generated without  
the .html at the end…

i tried

resources :pages, :format =\> :html

but i think the problem here is that html is the default mimetype and  
so it’s ignored. One sollution could be to set  
another mimetype as default so i would have to add the html format for  
every link i generate which would be ok for me…

---

<div class="post-metadata">

**Author:** ![gerold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f1d935/32.png) [@gerold](https://www.ruby-forum.com/u/gerold)\
**Post date:** [February 24, 2009, 1:31pm UTC](https://www.ruby-forum.com/t/add-html-extension-by-default/161220/4 "2009-02-24T13:31:17Z")

</div>

sounds a little bit silly, bit i just tried a route like  
map.connect ‘:controller/:action.html’  
that is actually working for me  
[http://localhost:3000/bla/index.html](http://localhost:3000/bla/index.html)

---

<div class="post-metadata">

**Author:** ![gerold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f1d935/32.png) [@gerold](https://www.ruby-forum.com/u/gerold)\
**Post date:** [February 24, 2009, 1:49pm UTC](https://www.ruby-forum.com/t/add-html-extension-by-default/161220/5 "2009-02-24T13:49:31Z")

</div>

> i would like to add the .html extension by default to all my  
> resources. What is the best way to do that? The reason for this is  
> that i need to download the generated sites via wget and i need  
> the .html extension for the downloaded files. Also it would be nice if  
> the link\_to would automatically generate the links with .html…

That’s a very bad idea. The better idea might be to add -E option to  
your  
wget call (and maybe -k too).

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![gerold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f1d935/32.png) [@gerold](https://www.ruby-forum.com/u/gerold)\
**Post date:** [February 24, 2009, 1:40pm UTC](https://www.ruby-forum.com/t/add-html-extension-by-default/161220/6 "2009-02-24T13:40:06Z")

</div>

i also figured that but i would really like to use resources…

---

<div class="post-metadata">

**Author:** ![gerold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f1d935/32.png) [@gerold](https://www.ruby-forum.com/u/gerold)\
**Post date:** [February 24, 2009, 2:12pm UTC](https://www.ruby-forum.com/t/add-html-extension-by-default/161220/7 "2009-02-24T14:12:30Z")

</div>

why is it a “very bad” idea? i don’t think that would be harmfull in  
any way. But if i can’t find an easy way to do it i will have to fix  
it with wget…

---

<div class="post-metadata">

**Author:** ![gerold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f1d935/32.png) [@gerold](https://www.ruby-forum.com/u/gerold)\
**Post date:** [February 24, 2009, 3:15pm UTC](https://www.ruby-forum.com/t/add-html-extension-by-default/161220/8 "2009-02-24T15:15:05Z")

</div>

> why is it a “very bad” idea? i don’t think that would be harmfull in  
> any way. But if i can’t find an easy way to do it i will have to fix  
> it with wget…

Well, sorry, but hacking application to get the result for the  
_external_ application (the same result you can get by adding two  
characters to the command line)  
does not sound like a good idea to me.

There are other reasons why file extensions are bad on the  
web in general and in REST case in particular, but I won’t go into  
that now.

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)
