[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Apache 2.2 rewrite rule help needed



On Mon, 2007-06-25 at 09:25 +0100, Bob Cox wrote:
> In article <[🔎] 20070624095129.GB899@hummingbird.wingbarscafe.com>,
> Jim Seymour <jim@wingbarscafe.com> wrote:
> 
> > Hi All,
> >
> > Running Apache 2.2 on Debian testing and having no luck getting a
> > rewrite rule to work. Straight out of the rewrite guide I am trying the
> > following to force the domain name to always be displayed as
> > www.domain.com even when it is accessed as domain.com.
> >
> > RewriteEngine on
> > RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
> > RewriteCond %{HTTP_HOST} !^$
> > RewriteRule ^/(.*) http://www.domain.com/$1 [L,R]
> >
> > I have tried many variations of this rule in both the apache virtual
> > configuration as well as an .htaccess file. I have verified via a dump
> > of the modules loaded that the rewrite module is loaded. The Options
> > FollowSymLinks is set and AllowOverride is set to FileInfo. I know the
> > .htaccess file is being read because I can put trash in it and it will
> > result in an Internal Server Error. Once the garbage is removed I can
> > load the web page without error. The rewrite rule never has an effect
> > and never gives any errors. Ideas?
> 
> I am not sure if this helps as I do the opposite, i.e. change all
> www.domain.com requests to domain.com.  I do it two ways.  On my own
> Apache server I do it this way:
> 
> <VirtualHost *>
> DocumentRoot /srv/www/htdocs/domain.com
> ServerName domain.com
> </VirtualHost>
> 
> <VirtualHost *>
> DocumentRoot /srv/www/htdocs/domain.com
> ServerName www.domain.com
> Redirect / http://domain.com/
> </VirtualHost>
> 
> and on a paid for hosting account using Rewrite (in a .htaccess file)
> this also works, but, again, to do the opposite of what you want:
> 
> RewriteEngine on
> rewritecond %{http_host} ^www\.domain\.com [nc]
> rewriterule ^(.*)$ http://domain.com/$1 [r=301,nc]
> 
> -- 
> Bob Cox.  Stoke Gifford, near Bristol, UK.
> http://pippin.co.uk/

Hi Bob,

Thanks. It would appear that in the apache suggested way [RewriteRule
^/(.*)], that the / after the ^ was the problem. It is now working just
as expected.

Thanks Again,

Jim



Reply to: