# URL Redirect and affect on Routes?

**URL:** <https://www.ruby-forum.com/t/url-redirect-and-affect-on-routes/165546>\
**Category:** Rails\
**Created:** [April 15, 2009, 4:44am UTC](https://www.ruby-forum.com/t/url-redirect-and-affect-on-routes/165546 "2009-04-15T04:44:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [April 15, 2009, 4:44am UTC](https://www.ruby-forum.com/t/url-redirect-and-affect-on-routes/165546/1 "2009-04-15T04:44:24Z")

</div>

I still don’t fully understand routes, so I apologize in advance.

I have a single rails app, but multiple domains pointing to different  
directories for marketing reasons. I am looking for a way to have the  
secondary domain point to the [primarydomain.com/directory](http://primarydomain.com/directory).

It’d want any links to [primarydomain.com/directory](http://primarydomain.com/directory) to 301 redirect to  
the secondary domain. Essentially, to the user everything should look  
like [SecondaryDomain.com is for sale | HugeDomains](http://secondarydomain.com/whatever) but be [primarydomain.com/directory/](http://primarydomain.com/directory/)  
whatever on the server.

How can I handle this without affecting routes?

Thanks,  
Jason

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [April 15, 2009, 5:16am UTC](https://www.ruby-forum.com/t/url-redirect-and-affect-on-routes/165546/2 "2009-04-15T05:16:34Z")

</div>

On Wed, Apr 15, 2009 at 4:43 AM, Jason [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> whatever on the server.
> 
> How can I handle this without affecting routes?
> 
> Thanks,  
> Jason

I would handle this in the upline webserver like Apache or Nginx with  
url rewriting

The primary domain can catch all calls to the directory and 301 them  
to the subdomain without passing the call through to Rails  
Rewrite the subdomain/whatever and pass it to RAILS/directory/whatever

This way Rails only has to deal with the call to the directory and can  
safely ignore the primary domain handling (and avoid changing routes)

Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)  
[http://www.linkedin.com/in/andrewtimberlake](http://www.linkedin.com/in/andrewtimberlake)

“I have never let my schooling interfere with my education” - Mark Twain

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [April 16, 2009, 4:59am UTC](https://www.ruby-forum.com/t/url-redirect-and-affect-on-routes/165546/3 "2009-04-16T04:59:54Z")

</div>

Thanks, I figured this should be a Rewrite rule but was not familiar  
enough with rails/routes to determine if I was making it more  
complicated. I feel pretty confident in working with Apache.

Thanks much!
