[Wylug-help] Apache .htaccess file.

Smylers Smylers at stripey.com
Fri Oct 16 22:34:39 UTC 2009


Douglas G Mckendrick writes:

> Hi all, and thanks for your replies.
> 
> > Try putting this line before all the above:
> > 
> >   RewriteEngine on
> 
> The above was already added to the file.

Good -- you didn't mention that in the original post, so it seemed worth
mentioning.

> Below is a copy of my file.
> 
> <IfModule mod_ssl.c>
> 	RewriteBase /d******.co.uk/
> </IfModule>
> <IfModule !mod_ssl.c>
> 	RewriteBase /
> </IfModule>

I'm guessing that mod_ssl isn't involved, so the second of those
RewriteBase directives is in effect.

> 	RewriteEngine On
>         RewriteRule ^([^.]*)$ index.cgi/$1 [L,NE]

You didn't mention that in your original post either!  In .htaccess
files the pattern is matched only against the 'filename' part -- that is
whatever follows the final slash in the URL, not the full path.  The
pattern ^([^.]*)$ matches every request that doesn't have a dot in it;
in particular it will match your homepage or any other directory index
page (which will have a completely empty filename part, which is good
enough to match that pattern).

The [L] at the end says this is the last RewriteRule to apply; any
RewriteRule-s further down the file will be ignored by any URLs which
matched this pattern.

> RewriteEngine On
> RewriteRule ^([^.]*)$ index.cgi/$1 [L]

That appears to be pointless duplication of the first rule, and isn't
doing anything; you can get rid of it.

> # For sites running on a port other than 80
> RewriteCond %{HTTP_HOST}   !^www\.d******\.co.uk [NC]
> RewriteCond %{HTTP_HOST}   !^$
> RewriteCond %{SERVER_PORT} !^80$
> RewriteRule ^/(.*)         http://www.d******.co.uk:%{SERVER_PORT}/$1
> [L,R]

That's even commented as not applying to you, so you can get rid of that
too.

> # 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]

That's never being reached because of the [L] on the first rule.  Put it
first (but after the RewriteEngine on) and it will have a chance of
working.

This rule also has an [L], so will be the last rule processed, but it
has [R] too -- meaning that this will make a user-visible redirect
through the browser to add on the missing "www.", which will make a
second request with the preferred domain name.  Second time around this
rule won't activate (because of the first RewriteCond above, which only
matches if this isn't www.d-etc.co.uk), and it will continue down to the
next rule, the index.cgi one.

(And next time please don't omit the part of your file which is actually
causing the problem -- we aren't psychic!)

Cheers.

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



More information about the Wylug-help mailing list