httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Don Edmondson" <>
Subject RE: [users@httpd] - mod_rewrite question
Date Sat, 18 May 2013 10:11:44 GMT
Don't know if I reply to the group or just to you?

> > RewriteCond $1.shtml -f
> This line doesnt make sense. What is $1 doing there what is it
> >RewriteRule    ^(kgp[a-z0-9]*)\.html$  $1.shtml [PT]

Sorry - not sure which line you are referring to - but, either way, it makes
perfect sense! It is a back-reference to the parenthesised expression
'kgp[a-z0-9]*'. As an example - if the requested URI is kgpwed.html then the
RewriteCond is checking if kgpwed.shtml exists and if it exists the
RewriteRule causes it to be passed to the client instead of kgpwed.html.
This can be seen in the trace...
With !-f
 [perdir D:/xampp/htdocs/] RewriteCond: input='kgpwed.shtml' pattern='!-f'
=> matched
 [perdir D:/xampp/htdocs/] rewrite 'kgpwed.html' -> 'kgpwed.shtml'
With -f
 [perdir D:/xampp/htdocs/] RewriteCond: input='kgpwed.shtml' pattern='-f' =>
 [perdir D:/xampp/htdocs/] pass through D:/xampp/htdocs/kgpwed.html

My problem is with the logic of '!-f' versus '-f' - my reading (and all
examples I've found) suggest that 
'!-f' means 'the file DOES NOT exist' and '-f' means 'the file DOES exist' -
but the actual operation (as shown in the traces) is the opposite behaviour.


From: Igor Cicimov [] 
Sent: 18 May 2013 03:35
To: users
Subject: Re: [users@httpd] - mod_rewrite question

On 18/05/2013 10:39 AM, "Don Edmondson" <>
> {hope I am doing this right!}
> I rewrote many of my pages for SSI (to use 'standard' headers and footers)
> but left the original .html files in situ. This was fine for a while - but
> find I am still getting a lot of hits on the .html files so decided to do
> something about it...
> Enter .htaccess and mod_rewrite. Struggled for a while but then accidently
> modified the .htaccess file - and made the rewrites work??
> What I wanted to do was wherever I had a .shtml file, any request for the
> .html version would be rewritten to .shtml - but I still have some files
> that are ONLY .html so didn't want these rewritten - simple enough (?) -
> check if .shtml exists and if yes rewrite uri - so my .htaccess looked
> like...
> RewriteEngine  on
> RewriteRule    ^index\.html$  index.shtml [PT]
> RewriteCond $1.shtml -f
This line doesnt make sense. What is $1 doing there what is it referencing?
> RewriteRule    ^(kgp[a-z0-9]*)\.html$  $1.shtml [PT]
> i.e. always rewrite index.html to index.shtml then for any files like
> kgp[something].html check if kgp[something].shtml exists and if yes then
> rewrite URI...
> ...but this doesn't work - the .html version of the file gets passed
> through?????
> The accidental edit on .htaccess however gave me
> RewriteEngine  on
> RewriteRule    ^index\.html$  index.shtml [PT]
> RewriteCond $1.shtml !-f
> RewriteRule    ^(kgp[a-z0-9]*)\.html$  $1.shtml [PT]
> i.e. I negated the RewriteCond with '!-f' - and the rewrite works as I
> ----
> ---but this is counter-intuitive?? - to me that RewriteCond reads as
> that kgp[something].shtml DOES NOT exist and if it doesn't then rewrite
> URI to kgp[something].shtml.
> I have done traces of both versions and the behaviour is exactly as I
> describe above -
> Can someone please explain where my thinking is going wrong (all examples
> I've looked at, everywhere, and also the .htaccess on my live website
> suggest that the first version of the .htaccess is correct - but the
> says otherwise - but I certainly don't want to implement this changed
> .htaccess on the live website until I understand what is happening :( )?
> Thanks and Regards
> Don Edmondson.
> 1 Osborne Close, Camberley, Surrey, GU16 9YD
> m:      07747 024 712
> t:      01252 642 626
> w:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message