httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Don Edmondson" <don.edmond...@kg-enterprises.com>
Subject [users@httpd] users@httpd.apache.org - mod_rewrite question
Date Sat, 18 May 2013 00:38:28 GMT
{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 I
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
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 want
----

---but this is counter-intuitive?? - to me that RewriteCond reads as 'Check
that kgp[something].shtml DOES NOT exist and if it doesn't then rewrite the
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 would
suggest that the first version of the .htaccess is correct - but the testing
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:	http://www.kg-enterprises.com






---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message