homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

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)

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)

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)


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)

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]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved