# Site redirection

**URL:** <https://www.ruby-forum.com/t/site-redirection/173053>\
**Category:** Rails\
**Created:** [August 1, 2009, 1:40am UTC](https://www.ruby-forum.com/t/site-redirection/173053 "2009-08-01T01:40:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [August 1, 2009, 1:40am UTC](https://www.ruby-forum.com/t/site-redirection/173053/1 "2009-08-01T01:40:16Z")

</div>

Hi there,

I use this in my .htaccess for redirect URL mysite.cr to www.mysite.cr.  
It redirects fine.

…  
…  
…  
RewriteEngine On  
RewriteCond %{HTTP\_HOST} ^mysite.cr [NC]  
RewriteRule ^(.\*)$ [http://www.mysite.cr/$1](http://www.mysite.cr/$1) [L,R=301]

But the first URL(the one that does not has www) stays without www  
even when it redircets properly. What i am trying to do is that no  
matter what URL somebody use( www.mysite.cr or mysite.cr), i want the  
final URL always to have www at the beginig.

Any idea?

Cheers

---

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [August 1, 2009, 2:41am UTC](https://www.ruby-forum.com/t/site-redirection/173053/2 "2009-08-01T02:41:08Z")

</div>

No need to use mod\_rewrite

RedirectMatch 301 ^/(.\*) http://…/$1

---

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [August 3, 2009, 6:48pm UTC](https://www.ruby-forum.com/t/site-redirection/173053/3 "2009-08-03T18:48:58Z")

</div>

hi,

ok i tryed with

RedirectMatch 301 ^/(.\*) http://…/$1

and it does not worked, in fact this solution loads the site without  
any css.

I am using the htaccess located in the public folder, do i have to  
configure something else for doing this???

Cheers

---

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [August 3, 2009, 7:01pm UTC](https://www.ruby-forum.com/t/site-redirection/173053/4 "2009-08-03T19:01:51Z")

</div>

another thing i am using passenger for my app, maybe passenger do not  
like .htaccess in public directory…no idea???

---

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [August 3, 2009, 8:02pm UTC](https://www.ruby-forum.com/t/site-redirection/173053/5 "2009-08-03T20:02:08Z")

</div>

even if i delete the htaccess(some say that passenger dont like  
htaccess) does not work

---

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [August 3, 2009, 8:48pm UTC](https://www.ruby-forum.com/t/site-redirection/173053/6 "2009-08-03T20:48:23Z")

</div>

I would use mod\_rewrite and not mod\_alias (RedirectMatch) for this  
task, and here is a example that will make sure you stay with www.

# Force [www.cadechristian.com](http://www.cadechristian.com)

RewriteCond %{HTTP\_HOST} !^www.cadechristian.com [NC]  
RewriteRule ^/(.\*) [http://www.cadechristian.com/$1](http://www.cadechristian.com/$1) [L,R=301]

This will always add the proper url with the leading www.

---

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [August 3, 2009, 9:18pm UTC](https://www.ruby-forum.com/t/site-redirection/173053/7 "2009-08-03T21:18:15Z")

</div>

in fact my first attempt was exactly what heimdull suggest. But it  
does not worked. I think this has to be somthing related with  
passenger…any other ideas?

---

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [August 4, 2009, 1:16am UTC](https://www.ruby-forum.com/t/site-redirection/173053/8 "2009-08-04T01:16:29Z")

</div>

i have created a"test" folder inside my application publuc folder.  
Inside test foler i have created one .htaccess file that redirects to  
[www.yahoo.com](http://www.yahoo.com) when i point my browser to it, redirects me to yahoo.  
But this htacces does not work inside my app’s public folder, it just  
do not do the redirect…
