RewriteCond for returning a 403?

What would the RewriteCond look like if I wanted to return a 403 to the client for all .html and .htm files requested?
LVL 3
rocketTendonAsked:
Who is Participating?
 
AndyAelbrechtCommented:
RewriteCond %{REQUEST_FILENAME} *\.htm*
RewriteRule ^/$ / [L,F]

should do it afaik
0
 
rocketTendonAuthor Commented:
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.
0
 
AndyAelbrechtCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.