I need to force all requests regardless of what they are to index.html. Unfortunately everything I have tried has not worked properly.

The following seems to me like it should work but it doesn't. My understanding is that it is saying for anything that doesn't end in /index.html to actually request the index.html file.

Redirect 302 !^/index.html http://www.example.com/index.html

Any help/clarification would be greatly appreciated.

3 Answers 3


Using an .htaccess on the root folder this should do the job:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule . /index.html [R=302,L]

The condition and rule is that if the request does not match index.html it will redirect whatever to it

  • Would you happen to know if it is possible to do this for all IPs except specified ones? Oct 7, 2010 at 15:28
  • You mean ip from those accessing the website or ips within the server ? update your question with an example of what you are looking for and i will check it out.
    – Prix
    Oct 7, 2010 at 20:22
  • Is there any way to make this work just for requests made on a subfolder of the root dir? SO that requesting www.site.com/folder/foo.php triggers the redirect while www.site.com/foo.php doesn't.
    – StepTNT
    Apr 3, 2013 at 9:06
  • Don't forget to set AllowOverride All in the Directory directive for the .htaccess to be taken into account. Mar 13, 2021 at 14:12

Answer of @prix is good. I myself needed to add conditions so that normal resources (images & css) are served as normal:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(css|gif|ico|jpg|js|png|swf|txt|svg|woff|ttf|eot)$
RewriteRule . index.html [L]
  • use 'RewriteCond %{HTTP_ACCEPT} text/html' instead of porn like 'RewriteCond %{REQUEST_URI} !\.(css|gif|ico|jpg|js|png|swf|txt|svg|woff|ttf|eot)$'
    – Yura
    Jun 18, 2021 at 13:46

I voted up the other answers, but in the end they didn't quite help me because I included a logo in the index.html file. So here are my adjustments. First of all, the prerequisites.


AllowOverride None


AllowOverride All


<Directory /var/www/>

to enable .htaccess file in /var/www/html (example).

Create or edit file


with content

RewriteEngine On

RewriteCond %{REQUEST_URI} ^.+/logo\.png$
RewriteRule . /logo.png [L]

RewriteCond %{REQUEST_URI} !^/index\.html$
RewriteCond %{REQUEST_URI} !^/logo\.png$
RewriteRule . /index.html [L]

As you can see, I'm not using a redirect. This means that the path or URI entered by the user remains the same; nevertheless, the index.html page is displayed with the logo.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .