# Subdomains and old urls

**URL:** <https://www.ruby-forum.com/t/subdomains-and-old-urls/134176>\
**Category:** Radiant CMS\
**Created:** [April 8, 2008, 5:09pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176 "2008-04-08T17:09:31Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 8, 2008, 5:09pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/1 "2008-04-08T17:09:31Z")

</div>

I’m currently moving my blog over to Radiant. I would like to preserve  
the  
old links if possible but at the same time move the blog part of the  
site to  
a subdomain [blog.randomutterings.com](http://blog.randomutterings.com). For example I wrote an article on  
redundant firewalls and the old url is  
[羞草研究所隐藏入口 - 羞含草研究研所2021 - 羞羞app正式版下载 - 羞羞动漫破解版无限金币](http://randomutterings.com/articles/2007/06/15/redundant-failover-firewall-with-pf-pfsync-and-carp-on-freebsdI)  
want the new url to be  
[http://blog.randomutterings.com/2007/06/15/redundant-failover-firewall-with-pf-pfsync-and-carp-on-freebsdbut](http://blog.randomutterings.com/2007/06/15/redundant-failover-firewall-with-pf-pfsync-and-carp-on-freebsdbut)  
at the same time I would like to have the old url forward the user to  
the new one if that is possible. Any suggestions are welcome.

–  
Chris B.  
[http://www.randomutterings.com](http://www.randomutterings.com)

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 8, 2008, 11:02pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/2 "2008-04-08T23:02:49Z")

</div>

Chris,

This sounds like a good candidate for an extension. The basic strategy  
would be to override either SiteController.show\_page or Page.find\_by\_url  
to search for a page that has the passed legacy URL (you’ll need to add  
a field in the database), in the case that the requested URL was not  
found. If a page is found, do a Permanent redirection (301 IIRC) to the  
new URL. If it isn’t found, pass through the FileNotFoundPage or  
exception.

Sean

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 8, 2008, 11:31pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/3 "2008-04-08T23:31:31Z")

</div>

I wouldn’t mind working on that if there were enough interest. Does  
anyone  
else need this? Also can someone help me to set the blog page of my  
site to  
use a subdomain?

On Tue, Apr 8, 2008 at 5:02 PM, Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > [http://randomutterings.com/articles/2007/06/15/redundant-failover-firewall-with-pf-pfsync-and-carp-on-freebsdI](http://randomutterings.com/articles/2007/06/15/redundant-failover-firewall-with-pf-pfsync-and-carp-on-freebsdI)  
> > Radiant mailing list  
> > Post: removed\_email\_address@domain.invalid  
> > Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> > Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
Chris B.

> **[羞草研究所隐藏入口 - 羞含草研究研所2021 - 羞羞app正式版下载 - 羞羞动漫破解版无限金币](http://www.randomutterings.com)**
>
> 羞草研究所隐藏入口,羞含草研究研所2021,羞羞app正式版下载,羞羞动漫破解版无限金币是一款最潮的手机短视频APP，提供ios苹果下载/安卓下载。片源丰富，高潮迭起！

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 9, 2008, 6:45am UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/4 "2008-04-09T06:45:39Z")

</div>

Chris B. wrote:

> I wouldn’t mind working on that if there were enough interest. Does anyone  
> else need this? Also can someone help me to set the blog page of my site to  
> use a subdomain?

Hi Chris,

Might be able to help with your second question but I’m not sure I  
understand it fully. What do you mean by:

> Also can someone help me to set the blog page of my site to  
> use a subdomain?

If you mean can it run like the way my Radiant site is running at  
[http://t-engine.onghu.com](http://t-engine.onghu.com) instead of htttp://www.onghu.com/ then I can  
help you with it.

Cheers  
Mohit.

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 9, 2008, 3:02pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/5 "2008-04-09T15:02:14Z")

</div>

My site runs under [www.randomutterings.com](http://www.randomutterings.com). The live site is still on  
typo  
so ignore that. Once I finish changing over to radiant, the blog will  
be at  
[www.randomutterings.com/blog/](http://www.randomutterings.com/blog/). I would like to make the blog run at  
[blog.randomutterings.com](http://blog.randomutterings.com) instead.

On Wed, Apr 9, 2008 at 12:43 AM, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Chris,  
> help you with it.

–  
Chris B.  
[http://www.randomutterings.com](http://www.randomutterings.com)

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 17, 2008, 5:50am UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/6 "2008-04-17T05:50:28Z")

</div>

I ended up leaving the blog on typo and its running at  
[blog.randomutterings.com](http://blog.randomutterings.com). The rest of the site is now on radiant at  
[www.randomutterings.com](http://www.randomutterings.com). Can anyone tell me the simplest way to do a  
301  
redirect in Radiant? I have 3 or 4 articles that moved to the blog  
subdomain and I would like to create pages in Radiant with their old  
urls  
and redirect them to the new ones.

On Wed, Apr 9, 2008 at 11:17 AM, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> OK, I fear I may not be able to help with that. If your blog (only) was  
> on Radiant, it would be quite simple. That’s the bit I’ve done ☹
> 
> Sorry but I think someone else will need to jump in here 😑
> 
> Cheers,  
> Mohit.  
> 4/9/2008 | 11:17 PM.

–  
Chris B.

> **[羞草研究所隐藏入口 - 羞含草研究研所2021 - 羞羞app正式版下载 - 羞羞动漫破解版无限金币](http://www.randomutterings.com)**
>
> 羞草研究所隐藏入口,羞含草研究研所2021,羞羞app正式版下载,羞羞动漫破解版无限金币是一款最潮的手机短视频APP，提供ios苹果下载/安卓下载。片源丰富，高潮迭起！

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 9, 2008, 5:19pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/7 "2008-04-09T17:19:41Z")

</div>

Chris B. wrote:

> My site runs under [www.randomutterings.com](http://www.randomutterings.com)  
> [http://www.randomutterings.com](http://www.randomutterings.com). The live site is still on typo so  
> ignore that. Once I finish changing over to radiant, the blog will be  
> at [www.randomutterings.com/blog/](http://www.randomutterings.com/blog/)  
> [http://www.randomutterings.com/blog/](http://www.randomutterings.com/blog/). I would like to make the blog  
> run at [blog.randomutterings.com](http://blog.randomutterings.com) [http://blog.randomutterings.com](http://blog.randomutterings.com)  
> instead.

OK, I fear I may not be able to help with that. If your blog (only) was  
on Radiant, it would be quite simple. That’s the bit I’ve done ☹

Sorry but I think someone else will need to jump in here 😑

Cheers,  
Mohit.  
4/9/2008 | 11:17 PM.

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 17, 2008, 3:31pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/8 "2008-04-17T15:31:47Z")

</div>

I may be dense here but I’m not getting it from the readme. How can I  
use  
the multi-site plugin to create 301 redirects?

On Thu, Apr 17, 2008 at 4:12 AM, Arik J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 301
> > 
> > > 
> > 
> > Chris B.  
> > [http://www.randomutterings.com](http://www.randomutterings.com)
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Radiant mailing list  
> Post: removed\_email\_address@domain.invalid  
> Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
Chris B.

> **[羞草研究所隐藏入口 - 羞含草研究研所2021 - 羞羞app正式版下载 - 羞羞动漫破解版无限金币](http://www.randomutterings.com)**
>
> 羞草研究所隐藏入口,羞含草研究研所2021,羞羞app正式版下载,羞羞动漫破解版无限金币是一款最潮的手机短视频APP，提供ios苹果下载/安卓下载。片源丰富，高潮迭起！

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 17, 2008, 3:47pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/9 "2008-04-17T15:47:07Z")

</div>

I did something similar for Redken… essentially create a new Page type  
called RedirectPage that does the redirection for you:

class RedirectPage \< Page  
def process(request, response)  
response.redirect(part(:body).content, “301 Moved Permanently”)  
end  
end

Then fill in the URL in the “body” part of the page and set the page  
type to “Redirect”. Of course, this will need to be in an extension.  
(Also, I’m not 100% positive on the syntax above, be sure to check.)

Sean

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 17, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/10 "2008-04-17T17:18:02Z")

</div>

How do you get the new page type to show as an option under page types  
in  
the radiant admin?

On Thu, Apr 17, 2008 at 9:45 AM, Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> to “Redirect”. Of course, this will need to be in an extension. (Also, I’m
> 
> > 301
> > 
> > > > 
> > > 
> > > 4/9/2008 | 11:17 PM.  
> > > Radiant mailing list  
> > > Post: removed\_email\_address@domain.invalid  
> > > Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> > > Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
Chris B.

> **[羞草研究所隐藏入口 - 羞含草研究研所2021 - 羞羞app正式版下载 - 羞羞动漫破解版无限金币](http://www.randomutterings.com)**
>
> 羞草研究所隐藏入口,羞含草研究研所2021,羞羞app正式版下载,羞羞动漫破解版无限金币是一款最潮的手机短视频APP，提供ios苹果下载/安卓下载。片源丰富，高潮迭起！

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 17, 2008, 5:23pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/11 "2008-04-17T17:23:05Z")

</div>

Chris B. wrote:

> How do you get the new page type to show as an option under page types  
> in the radiant admin?

The way I’ve done it in the past is (example from my Schools extension):

In …/schools/schools\_extension.rb

def activate  
admin.tabs.add “Schools”, “/manage/schools”, :after =\> “Layouts”,  
:visibility =\> [:all]  
SchoolPage  
end

In …/schools/app/models/school\_page.rb

class SchoolPage \< Page  
…  
…  
…  
end

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 17, 2008, 10:12am UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/12 "2008-04-17T10:12:59Z")

</div>

Checkout the multi-site plugin below. I think it would work well for  
what you need. 🙂

[http://svn.radiantcms.org/radiant/trunk/extensions/multi\_site/README](http://svn.radiantcms.org/radiant/trunk/extensions/multi_site/README)

Chris B. wrote:

> I ended up leaving the blog on typo and its running at  
> [blog.randomutterings.com](http://blog.randomutterings.com). The rest of the site is now on radiant at  
> [www.randomutterings.com](http://www.randomutterings.com). Can anyone tell me the simplest way to do a  
> 301  
> redirect in Radiant? I have 3 or 4 articles that moved to the blog  
> subdomain and I would like to create pages in Radiant with their old  
> urls  
> and redirect them to the new ones.
> 
> On Wed, Apr 9, 2008 at 11:17 AM, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > OK, I fear I may not be able to help with that. If your blog (only) was  
> > on Radiant, it would be quite simple. That’s the bit I’ve done ☹
> > 
> > Sorry but I think someone else will need to jump in here 😑
> > 
> > Cheers,  
> > Mohit.  
> > 4/9/2008 | 11:17 PM.
> 
> –  
> Chris B.  
> [http://www.randomutterings.com](http://www.randomutterings.com)

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 17, 2008, 5:25pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/13 "2008-04-17T17:25:02Z")

</div>

David P. wrote:

> Chris B. wrote:
> 
> > How do you get the new page type to show as an option under page types  
> > in the radiant admin?
> 
> The way I’ve done it in the past is (example from my Schools extension):
> 
> In …/schools/schools\_extension.rb
> 
> def activate  
> admin.tabs.add “Schools”, “/manage/schools”, :after =\> “Layouts”,  
> :visibility =\> [:all]  
> SchoolPage  
> end
> 
> In …/schools/app/models/school\_page.rb
> 
> class SchoolPage \< Page  
> …  
> …  
> …  
> end

Given Sean’s example, I believe you would do…

def activate  
RedirectPage  
end

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 17, 2008, 5:26pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/14 "2008-04-17T17:26:52Z")

</div>

Chris,

You’ll need to make an extension, first, put the page class in the  
extension under app/models, and then “mention” it in the activate method  
of your extension class, like so:

class RedirectExtension \< Radiant::Extension  
#…  
def activate  
RedirectPage  
end  
end

At some point, I’d like to have extensions automatically load page  
classes, but that may be a feature for the next release.

Sean

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 17, 2008, 7:27pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/15 "2008-04-17T19:27:28Z")

</div>

This is great stuff guys, thanks. I have it all working but it  
redirects  
“302 Found” even if I use the following.

response.redirect(part(:body).content, “301 Moved Permanently”

I’ve tried googling for answers but all I can find on redirecting 301 in  
ruby is to use redirect\_to which is not available in the model. Any  
suggestions?

On Thu, Apr 17, 2008 at 11:25 AM, Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> end
> 
> > How do you get the new page type to show as an option under page types
> > 
> > > called RedirectPage that does the redirection for you:  
> > > (Also, I’m
> > > 
> > > > [blog.randomutterings.com](http://blog.randomutterings.com). The rest of the site is now on radiant at
> > > > 
> > > > > > My site runs under [www.randomutterings.com](http://www.randomutterings.com) \<

–  
Chris B.

> **[羞草研究所隐藏入口 - 羞含草研究研所2021 - 羞羞app正式版下载 - 羞羞动漫破解版无限金币](http://www.randomutterings.com)**
>
> 羞草研究所隐藏入口,羞含草研究研所2021,羞羞app正式版下载,羞羞动漫破解版无限金币是一款最潮的手机短视频APP，提供ios苹果下载/安卓下载。片源丰富，高潮迭起！

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [April 17, 2008, 7:59pm UTC](https://www.ruby-forum.com/t/subdomains-and-old-urls/134176/16 "2008-04-17T19:59:45Z")

</div>

I’ve got it built but its only doing 302 redirects until I figure out  
how to  
pass a status into response.redirect but I went ahead and released it  
anyway.

> **[羞草研究所隐藏入口 - 羞含草研究研所2021 - 羞羞app正式版下载 - 羞羞动漫破解版无限金币](http://www.randomutterings.com/projects/page_redirect/)**
>
> 羞草研究所隐藏入口,羞含草研究研所2021,羞羞app正式版下载,羞羞动漫破解版无限金币是一款最潮的手机短视频APP，提供ios苹果下载/安卓下载。片源丰富，高潮迭起！

I’m open to opinions and suggestions on the code and also writing a test  
for  
it. You can see my attempts in the source.

On Thu, Apr 17, 2008 at 1:26 PM, Chris B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On Thu, Apr 17, 2008 at 11:25 AM, Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> > def activate  
> > Chris B. wrote:
> > 
> > > > I did something similar for Redken… essentially create a new Page  
> > > > type
> > > > 
> > > > > urls
> > > > > 
> > > > > > > [www.randomutterings.com/blog/](http://www.randomutterings.com/blog/) \<  
> > > > > > > (only)
> > > > 
> > > > Post: removed\_email\_address@domain.invalid
> 
> Chris B.  
> [http://www.randomutterings.com](http://www.randomutterings.com)

–  
Chris B.  
[http://www.randomutterings.com](http://www.randomutterings.com)
