RewriteCond for returning a 403?

Posted on 2006-04-06
Medium Priority
Last Modified: 2010-05-18
What would the RewriteCond look like if I wanted to return a 403 to the client for all .html and .htm files requested?
Question by:rocketTendon
  • 2

Accepted Solution

AndyAelbrecht earned 2000 total points
ID: 16398648
RewriteCond %{REQUEST_FILENAME} *\.htm*
RewriteRule ^/$ / [L,F]

should do it afaik

Author Comment

ID: 16401381
Will this work even if the html file doesn't exist?

I am still getting a 404 error for html files after I add that code.

Expert Comment

ID: 16612546
I like to add 1 more thing as the original OP stated his problem wasn't actually solved.
I made a small mistake in my RewriteRule:

Options +FollowSymLinks   ##use SymLinks pls (this is best on when using the RewriteEngine)
RewriteEngine On    ##puts the Rewrite Engine On, obviously
RewriteCond %{REQUEST_FILENAME} *\.htm*    ##this checks for any *.htm* file (catching *.html on the way)
RewriteRule ^/$ / [F]    ##rewrite the complete URL to the base url (/); F stands for forbidden (403) (the L in my first reply was for Last command, obviously in the wrong place and not needed)

You could write the RewriteRule also as:
RewriteRule .* - [F]
which is another way of using the wildcards.

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question