RewriteCond for returning a 403?

Posted on 2006-04-06
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
    LVL 4

    Accepted Solution

    RewriteCond %{REQUEST_FILENAME} *\.htm*
    RewriteRule ^/$ / [L,F]

    should do it afaik
    LVL 3

    Author Comment

    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.
    LVL 4

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now