# 301 Redirects (and stripping out www/subdomains)

**URL:** <https://www.ruby-forum.com/t/301-redirects-and-stripping-out-www-subdomains/92836>\
**Category:** Radiant CMS\
**Created:** [April 24, 2007, 9:10pm UTC](https://www.ruby-forum.com/t/301-redirects-and-stripping-out-www-subdomains/92836 "2007-04-24T21:10:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zara](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b9bd4f/32.png) [@Zara](https://www.ruby-forum.com/u/Zara)\
**Post date:** [April 24, 2007, 9:10pm UTC](https://www.ruby-forum.com/t/301-redirects-and-stripping-out-www-subdomains/92836/1 "2007-04-24T21:10:13Z")

</div>

First of all, apologies in advance for such a n00b question.

I’ve just performed a fresh install of Radiant 0.6

My usual practice when setting up a site is to immediately strip www  
from the URL (via mod rewrite and a 301 redirect), however my attempts  
to modify the .htaccess file in Radiants ‘public’ folder have  
accomplished nothing.

.htaccess is currently as it was immediately after install. My current  
issue is that the following URL’s all serve the same page:

[http://example.com](http://example.com)  
[http://www.example.com](http://www.example.com)  
[http://anythingelseyoucaretotry.example.com](http://anythingelseyoucaretotry.example.com)

Does anyone have any suggestions as to how I can accomplish my goal? I  
don’t expect to be hand-held, but if there are resources that I’ve  
overlooked I’d appreciate a shove in the right direction. (A trawl of  
the web and assorted forums hasn’t produced any relevant info).

Thanks in advance.

# P.S.

# I’m using Media Temple. The following can be found immediately after ‘RewriteEngine On’.

#MTSTART – Automatically generated, don’t modify –  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(.\*)$ [http://xx.x.xxx.xxx:2010/${escape:$1}](http://xx.x.xxx.xxx:2010/$%7Bescape:$1%7D) [P]  
#MTEND

---

<div class="post-metadata">

**Author:** ![Zara](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b9bd4f/32.png) [@Zara](https://www.ruby-forum.com/u/Zara)\
**Post date:** [April 26, 2007, 3:29pm UTC](https://www.ruby-forum.com/t/301-redirects-and-stripping-out-www-subdomains/92836/2 "2007-04-26T15:29:48Z")

</div>

> My current issue is that the following URL’s all serve the same page:
> 
> [http://example.com](http://example.com)  
> [http://www.example.com](http://www.example.com)  
> [http://anythingelseyoucaretotry.example.com](http://anythingelseyoucaretotry.example.com)

> I’m using Media Temple.

Likewise, on both counts. (Although I feel this is a Rails/MT issue  
rather than a Radiant one).

I’m not convinced editing the .htaccess file is even the way to go in  
this situation; given the ‘automatically generated’ MT code is already  
rewriting the URL through a proxy.

Please excuse my ignorance, I’m new to both RoR & Radiant, but a one  
word yes/no answer from someone with knowledge of the platform would be  
extremely helpful.

Anyone?

---

<div class="post-metadata">

**Author:** ![Zara](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b9bd4f/32.png) [@Zara](https://www.ruby-forum.com/u/Zara)\
**Post date:** [April 26, 2007, 3:47pm UTC](https://www.ruby-forum.com/t/301-redirects-and-stripping-out-www-subdomains/92836/3 "2007-04-26T15:47:41Z")

</div>

Hi Suzanne,

This is something that you could be handling quite easily in your web  
server  
rather than in your application. In Apache for example, adding the  
following  
right after the “RewriteEngine On” line would achieve what you want:

# Redirect [non-mydomain.co.uk](http://non-mydomain.co.uk) domains

RewriteCond %{HTTP\_HOST} .  
RewriteCond %{HTTP\_HOST} !^mydomain.co.uk  
RewriteRule (.\*) [http://mydomain.co.uk/$1](http://mydomain.co.uk/$1) [R=301,L]

After this you should have the default Rails/Radiant content and  
everything  
will get picked up correctly as the above code is only processed when  
the  
domain does not match your wanted domain and halts processing after the  
redirect when it doesn’t.

Best Regards,  
Kevin A.

---

<div class="post-metadata">

**Author:** ![Zara](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b9bd4f/32.png) [@Zara](https://www.ruby-forum.com/u/Zara)\
**Post date:** [April 26, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/301-redirects-and-stripping-out-www-subdomains/92836/4 "2007-04-26T19:32:14Z")

</div>

Or you can use this if you are using lighttpd

# from any www.host (with www.) to the host (without www.)

$HTTP[“host”] =~ “^www.(._)" {  
url.redirect = ( "^/(._)” =\> “http://%1/$1” )  
}

another good place to look is  
[http://no-www.org/](http://no-www.org/)

Martin

---

<div class="post-metadata">

**Author:** ![Zara](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b9bd4f/32.png) [@Zara](https://www.ruby-forum.com/u/Zara)\
**Post date:** [April 26, 2007, 8:29pm UTC](https://www.ruby-forum.com/t/301-redirects-and-stripping-out-www-subdomains/92836/5 "2007-04-26T20:29:16Z")

</div>

> right after the “RewriteEngine On” line would achieve what you want:
> 
> # Redirect [non-mydomain.co.uk](http://non-mydomain.co.uk) domains
> 
> RewriteCond %{HTTP\_HOST} .  
> RewriteCond %{HTTP\_HOST} !^mydomain.co.uk  
> RewriteRule (.\*) [http://mydomain.co.uk/$1](http://mydomain.co.uk/$1) [R=301,L]
> 
> After this you should have the default Rails/Radiant content and  
> everything  
> will get picked up correctly as the above code is only processed when  
> the  
> domain does not match your wanted domain and halts processing after the  
> redirect when it doesn’t.
> 
> Best Regards,  
> Kevin A.

Thanks for replying, Kevin.

Your example is virtually identical to how I normally re-write URL’s.  
However, I may have misinterpreted what the original poster was  
attempting, allow me to elaborate…

When a Rails app is installed on a MT grid server the html/public\_html  
folder is removed from that of the domain and replaced with a sym link  
to the app. Which is why I thought the poster may have been trying to  
place the re-write rule before the (quoted) ‘automatically generated’  
Media Temple code. Because, obviously, dropping an .htaccess complete  
with re-write rules into the domain folder wont do a thing.

Personally, I have a few other approaches to try before I resort to tech  
support, but if anyone has suggestions, I’d welcome them.

Thanks, Suzanne.
