Account Options

  1. Sign in
Google Groups Home
« Groups Home
Adding (or removing) "www" without mod_rewrite
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Peter Cooper  
View profile  
 More options Aug 7 2008, 2:39 am
From: Peter Cooper <pcoo...@gmail.com>
Date: Wed, 6 Aug 2008 23:39:46 -0700 (PDT)
Local: Thurs, Aug 7 2008 2:39 am
Subject: Adding (or removing) "www" without mod_rewrite
How do other Passenger users deal with removing or adding "www" to
their URLs without using mod_rewrite?

For example, if I have a site http://www.example.com/, I might want
all visitors to http://example.com/ to redirect to http://www.example.com/
(or vice versa). This is recommended for SEO purposes to help prevent
duplicate content being detected. Normally you'd use a rewrite rule
with a host-based condition to deal with this, but is there a way of
doing it without activating mod_rewrite?

I could always activate mod_rewrite and deal with it the classic way,
but since it's hinted that this isn't a Good Thing (tm) to do, I'd
like to avoid doing that.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Cooper  
View profile  
 More options Aug 7 2008, 6:02 am
From: Peter Cooper <pcoo...@gmail.com>
Date: Thu, 7 Aug 2008 03:02:57 -0700 (PDT)
Local: Thurs, Aug 7 2008 6:02 am
Subject: Re: Adding (or removing) "www" without mod_rewrite
On Aug 7, 7:39 am, Peter Cooper <pcoo...@gmail.com> wrote:

> How do other Passenger users deal with removing or adding "www" to
> their URLs without using mod_rewrite?

> For example, if I have a sitehttp://www.example.com/, I might want
> all visitors tohttp://example.com/to redirect tohttp://www.example.com/
> (or vice versa). This is recommended for SEO purposes to help prevent
> duplicate content being detected. Normally you'd use a rewrite rule
> with a host-based condition to deal with this, but is there a way of
> doing it without activating mod_rewrite?

> I could always activate mod_rewrite and deal with it the classic way,
> but since it's hinted that this isn't a Good Thing (tm) to do, I'd
> like to avoid doing that.

Just to add in case it's useful for someone else, a few people have
suggested on Twitter having two virtual hosts, one for www and one
without, and then using a simple Redirect on one. That's not
acceptable in my case as I'm using cPanel and don't want to mess with
the VirtualHosts if I can avoid it (in which case mod_rewrite
reactivation is a better option).

Pete


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Stone  
View profile  
 More options Aug 7 2008, 7:35 am
From: "Andrew Stone" <stoneli...@gmail.com>
Date: Thu, 7 Aug 2008 07:35:45 -0400
Local: Thurs, Aug 7 2008 7:35 am
Subject: Re: Adding (or removing) "www" without mod_rewrite

Hey Peter,

Couldn't you use a before_filter on the application controller to test the
request?  I do something similar for an ssl requiremet for specific
controllers like:

    def redirect_to_ssl
      return if request.ssl?

      unless (request.ssl? or RAILS_ENV == 'development')
          redirect_to(url_for(params.merge({:protocol => 'https://'})))
      end

    end

Of course the before_filter is redirect_to_ssl.

Good luck,
andy

--
Andrew Stone


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
RSL  
View profile  
 More options Aug 7 2008, 8:19 am
From: RSL <sco...@gmail.com>
Date: Thu, 7 Aug 2008 08:19:54 -0400
Local: Thurs, Aug 7 2008 8:19 am
Subject: Re: Adding (or removing) "www" without mod_rewrite
Yes. You can indeed redirect based on if request.subdomains.first ==
"www". I've had to do so in the past when I couldn't change the Apache
confs. It will cost an extra Rails request though, so if you can solve
it by rewriting the configurations, that's probably preferable.

RSL


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Stone  
View profile  
 More options Aug 7 2008, 8:37 am
From: "Andrew Stone" <stoneli...@gmail.com>
Date: Thu, 7 Aug 2008 08:37:54 -0400
Local: Thurs, Aug 7 2008 8:37 am
Subject: Re: Adding (or removing) "www" without mod_rewrite

On Thu, Aug 7, 2008 at 8:19 AM, RSL <sco...@gmail.com> wrote:

> Yes. You can indeed redirect based on if request.subdomains.first ==
> "www". I've had to do so in the past when I couldn't change the Apache
> confs. It will cost an extra Rails request though, so if you can solve
> it by rewriting the configurations, that's probably preferable.

> RSL

It would only cost you an extra request one time though.  After it is set,
you should be good.   You will have to test each request or store something
in the session to flag that the test has been done.  I'm guessing storing a
true/false value in the session to denote whether the test has been done
will be faster than testing the actual request.subdomains for "www" every
time.

--
Andrew Stone


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
secobarbital  
View profile  
 More options Aug 10 2008, 1:44 am
From: secobarbital <seggy.um...@gmail.com>
Date: Sat, 9 Aug 2008 22:44:39 -0700 (PDT)
Local: Sun, Aug 10 2008 1:44 am
Subject: Re: Adding (or removing) "www" without mod_rewrite
On Aug 6, 11:39 pm, Peter Cooper <pcoo...@gmail.com> wrote:

> I could always activate mod_rewrite and deal with it the classic way,
> but since it's hinted that this isn't a Good Thing (tm) to do, I'd
> like to avoid doing that.

Isn't mod_rewrite overridden because of the default .htaccess that is
generated by Rails?

http://www.modrails.com/documentation/Users%20guide.html#conflicting_...
"If you really want to use mod_rewrite on Rails virtual hosts, then
please set the RailsAllowModRewrite configuration option. But please
note that you will have to delete Rails applications'
default .htaccess file, or add rewrite rules to negate its effects."


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Cooper  
View profile  
 More options Aug 10 2008, 7:40 am
From: Peter Cooper <pcoo...@gmail.com>
Date: Sun, 10 Aug 2008 04:40:06 -0700 (PDT)
Local: Sun, Aug 10 2008 7:40 am
Subject: Re: Adding (or removing) "www" without mod_rewrite

On Aug 10, 6:44 am, secobarbital <seggy.um...@gmail.com> wrote:

> On Aug 6, 11:39 pm, Peter Cooper <pcoo...@gmail.com> wrote:

> > I could always activate mod_rewrite and deal with it the classic way,
> > but since it's hinted that this isn't a Good Thing (tm) to do, I'd
> > like to avoid doing that.

> Isn't mod_rewrite overridden because of the default .htaccess that is
> generated by Rails?

I believe so, but there was a discussion here recently asking whether
that's the only reason why and, if not, what the other problem cases
were. I don't recall seeing an answer to that, so there might be edge
cases that could be thrown up by reactivating it. It's certainly worth
a try though.

Many thanks to Andrew and RSL, I hadn't thought of doing it at the app
level but that makes sense - thanks!

Pete


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scotttt  
View profile  
 More options Sep 5 2008, 3:42 am
From: Scotttt <scot...@gmail.com>
Date: Fri, 5 Sep 2008 00:42:11 -0700 (PDT)
Local: Fri, Sep 5 2008 3:42 am
Subject: Re: Adding (or removing) "www" without mod_rewrite

> I believe so, but there was a discussion here recently asking whether
> that's the only reason why and, if not, what the other problem cases
> were. I don't recall seeing an answer to that, so there might be edge
> cases that could be thrown up by reactivating it. It's certainly worth
> a try though.

> Many thanks to Andrew and RSL, I hadn't thought of doing it at the app
> level but that makes sense - thanks!

> Pete

Hi Pete -

Have you written any code for this yet? Would you share if you have?
I'm looking at the same issue and was going to put something together
tomorrow, but if you've already solved it, so much the better. I think
this may become a popular thread over time. :)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
RSL  
View profile  
 More options Sep 5 2008, 10:03 am
From: RSL <sco...@gmail.com>
Date: Fri, 5 Sep 2008 10:03:03 -0400
Local: Fri, Sep 5 2008 10:03 am
Subject: Re: Adding (or removing) "www" without mod_rewrite

Here's what I'm using:

# before_filter :trim_www

def trim_www
  if request.subdomains.first == "www"
    if request.subdomains == ["www"]
      redirect_to "#{request.protocol}#{request.
domain}#{request.port_string}#{request.path}"
    else
      subdomains = request.subdomains.shift.join(".")
      subdomains << "." unless subdomains.blank?
      redirect_to
"#{request.protocol}#{subdomains}#{request.domain}#{request.port_string}#{r equest.path}"
    end
  end
end

RSL


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scotttt  
View profile  
 More options Sep 5 2008, 5:27 pm
From: Scotttt <scot...@gmail.com>
Date: Fri, 5 Sep 2008 14:27:41 -0700 (PDT)
Local: Fri, Sep 5 2008 5:27 pm
Subject: Re: Adding (or removing) "www" without mod_rewrite
This worked great. Thanks!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »