Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod rewrite - deny certain file extension

Ask for .htm but show .tml - if requested directly as .tml dont show file



11:43 am on Jun 20, 2003 (gmt 0)

10+ Year Member

In my weblibary I have some .tml files, that I would like to be not accessible from the outside - only when requested as .htm pages.

I already use the code below and it works fine.

The code works as follows: If a user asks for example.htm he will get example.tml if it exits. If the example.tml file does not exits we look after the same filename but with the .htm extension and the user will get that file.

What I need is a small piece of code that will tell the user, that if he asks directly for example.tml he will be told that the file does not exits.


RewriteRule ^(.*)\.htm$ $1 [C,E=OkHTM:yes]
RewriteCond %{REQUEST_FILENAME}.tml -f
RewriteRule ^(.*)$ $1.tml [S=1]
RewriteCond %{ENV:OkHTM} ^yes$
RewriteRule ^(.*)$ $1.htm


9:55 pm on Jun 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Would something like this work at the beginning of your list?

RewriteRule ^(.*)\.tml$ yourerrorpage.htm [L]


8:41 am on Jun 23, 2003 (gmt 0)

10+ Year Member


Sorry, the code doesn't work as intended.

When the code is executed, it works fine when I ask for a .tml file - the errorpage is shown. But when I ask for a .htm page that exsists as a .tml page I also get the errorpage - proberly because the code is executed one time more (the .tml file is requested and travels the way down the code - and already gets a hit at line one...)


2:27 pm on Jun 23, 2003 (gmt 0)

10+ Year Member

I have rewritten the code and use it a bit different now.

All the .tml files have been moved to the folder /tml and the code works like this: When a .htm page is requested and not found (no matter the filepath), the page is requested as a .tml file in the folder /tml and shown with the first requested path/adress.

RewriteCond %{REQUEST_FILENAME}.htm !-f
RewriteRule ([^/]+.)htm$ /tml/$1tml [L]


Featured Threads

Hot Threads This Week

Hot Threads This Month