Redirect all HTML pages to home page with .htaccess

Posted on 2011-05-03
Last Modified: 2012-05-11
I need to temporarily redirect all files on a web site with the extension .htm or .html to the home page (index.html)

I have tried this:

RewriteEngine On
RewriteRule ^.*\.htm$ /index.html [R=302,L]

But this is adding the document root to the home page path (and also only works for .htm).

Help please!
Question by:PaliTree
    LVL 9

    Expert Comment


    RewriteEngine On
    RewriteRule ^/.* / [R=302,L]

    Open in new window


    Author Comment

    But that redirects everything surely!

    I only want to redirect *.htm and *.html. And I DON'T want to redirect index.html to itself!
    LVL 9

    Accepted Solution

    Ah, ok, I see now.  Try:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/index.html$
    RewriteRule ^.*\.ht(m|ml)$ /index.html [R=302,L]

    Open in new window


    Author Comment

    That's it!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
    Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 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

    7 Experts available now in Live!

    Get 1:1 Help Now