[Wylug-help] Apache .htaccess file.

Smylers Smylers at stripey.com
Sun Oct 18 20:48:05 UTC 2009


Douglas G Mckendrick writes:

> I have altered my htaccess file as below, but it still isn't doing as
> I want. 
> 
> <IfModule mod_ssl.c>
> 	RewriteBase /d******.co.uk/
> </IfModule>
> <IfModule !mod_ssl.c>
> 	RewriteBase /
> </IfModule>
> 	RewriteEngine On
> 	# And for a site running on port 80
> 	RewriteCond %{HTTP_HOST}   !^www\.d******\.co.uk [NC]
> 	RewriteCond %{HTTP_HOST}   !^$
> 	RewriteRule ^/(.*)         http://www.d******.co.uk/$1 [L,R]
>         RewriteRule ^([^.]*)$ index.cgi/$1 [L,NE]
> RewriteEngine On

> Looking at johns website, www remains at the front, so I don't think I
> would need to change the rewrite cond and rule around.  Do I need to
> omit the /www in the first rewrite cond rule?

No -- the ! in the patterns means 'not', so the first RewriteCond is
saying 'if the server name isn't www.domain.co.uk', which is what you
want.  (Pedantically all three dots should have a backslash before them,
not just the first two, and a dollar and the end would be good as well.
But neither of those would affect it matching domain.co.uk without the
leading "www.".)

The above looks to me like it should work.

At this stage the next thing I'd do is put in some logging, to see what
actually is happening.  Unfortunately it looks like RewriteLog can't be
used in .htaccess files -- the 'context' line says only 'server config,
virtual host':

  http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog

If you have root access to the server then use RewriteLog and
RewriteLogLevel to log mod_rewrite activity, make a few requests and see
what they're saying.

Smylers
-- 
http://twitter.com/Smylers2



More information about the Wylug-help mailing list