Using mod_rewrite to add 'www' to urls

Hi guys. I’m using the following rule to point users to www.mydomain.com
instead of mydomain.com.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,QSA,L]

But it doesn’t work. Accessing mydomain.com yields just that.

Any ideas?

On 5/17/07, Daniel W. [email protected] wrote:

Hi guys. I’m using the following rule to point users to www.mydomain.com
instead of mydomain.com.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,QSA,L]

But it doesn’t work. Accessing mydomain.com yields just that.

Here’s a working version I have on my laptop:

RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteRule ^(.*)$ http://www.localhost/$1 [L,R=301]


Greg D.
http://destiney.com/

Greg D. wrote:

RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteRule ^(.*)$ http://www.localhost/$1 [L,R=301]

Nay, still not working. No errors, no time outs, httpd restarts okay. It
just doesn’t write ‘www’ into the address bar.

Initially I was putting these rules right above my vhost directive. I
then tried moving it into my vhost directive directly beneath the
RewriteEngine On part.

=(

On 5/17/07, Daniel W. [email protected] wrote:

RewriteEngine On part.
Yeah, you have to use those rules first or some other rules might fire
first instead.

Does this help?

RewriteLogLevel 9
RewriteLog logs/rewrite.log


Greg D.
http://destiney.com/

Greg D. wrote:

Does this help?

RewriteLogLevel 9
RewriteLog logs/rewrite.log

Nay. I assume it would create the logs directory if it didn’t already
exist? It doesn’t.

By the way, I dig your site. :slight_smile:

Hi guest. I thought about that before posting, but I figured I would
post here in case anyone using Rails has come across some weirdness with
Rails and mod_rewrite.

Alas, your suggestion is valid, and I shall go find an Apache tribe to
talk to.

post.gsub!(/RoR: Talk/, “Apache: Talk”)

On May 17, 1:35 pm, Daniel W. [email protected]

Greg D. wrote:

Does this help?

RewriteLogLevel 9
RewriteLog logs/rewrite.log

Nay. I assume it would create the logs directory if it didn’t already
exist? It doesn’t.

No, it won’t create the logs directory if it doesn’t exist…

On 5/17/07, Daniel W. [email protected] wrote:

Greg D. wrote:

Does this help?

RewriteLogLevel 9
RewriteLog logs/rewrite.log

Nay. I assume it would create the logs directory if it didn’t already
exist? It doesn’t.

I always have to make an explicit entry to get rewrite logs.

By the way, I dig your site. :slight_smile:

Thanks. It’s just a little something I threw together one afternoon.
:slight_smile:


Greg D.
http://destiney.com/

Out of curiosity, why would you want to make the canonical URI have www
appended to it? For me, it seems so antiquated like ooooh double u
double u
double u dot … That’s just me though. I’m legitimately curious about
any
benefits [perceived or actual] for the extra www.

RSL

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs