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.
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).
On Thu, Aug 7, 2008 at 6:02 AM, Peter Cooper <pcoo...@gmail.com> wrote:
> 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).
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
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.
On Thu, Aug 7, 2008 at 7:35 AM, Andrew Stone <stoneli...@gmail.com> wrote:
> On Thu, Aug 7, 2008 at 6:02 AM, Peter Cooper <pcoo...@gmail.com> wrote:
>> 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).
> 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
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.
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."
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!
> 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. :)
On Fri, Sep 5, 2008 at 3:42 AM, Scotttt <scot...@gmail.com> wrote:
> > 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. :)