Redirect each request to index page

.htaccessapache-2.2redirect

I'm trying to redirect all the user's requests to my index page, except the one made to the root folder.

So www.domain.com/page.ext is fine while www.domain.com/folder/page.ext has to be redirected.

Here's my .htaccess:

RewriteEngine on
RewriteRule ^([^/]+)/?$ /index.html [L]
ErrorDocument 404 /index.html

It causes an Internal Server Error and I don't know why.

Basically I want to force the user to access just the index.html page in every kind of situation.

Suggestions?

EDIT:

Just to give some more infos, here's my site structure:

/
|-- index.html
|-- css
   |-- site.css
|-- js
   |-- site.js
|-- images
   |-- img1.png
   |-- img2.png
   |-- img3.png

As you can see it's really simple.

What I need to do is to show always my index.html (which uses css/site.css, js/site.js and the images are used in the css)

So it doesn't matter what page the user requests, my site must show the index one.
This means that the index has to be shown even in case of 404 error and even if the user requests a page in a folder which doesn't exists!

Best Answer

Within an .htaccess file, the relative path to the directory (or the RewriteBase, if one is configured) is used for both the match string (you've got that right in your regex, no leading slash) and the replace string.

Try RewriteRule ^([^/]+)/?$ index.html [L]

Edit:

To avoid doing this for your image/js/css files, you can use RewriteCond to prevent the rule from being applied:

RewriteCond %{REQUEST_URI} !^/images [NC]
RewriteCond %{REQUEST_URI} !^/css [NC]
RewriteCond %{REQUEST_URI} !^/js [NC]
RewriteRule ^([^/]+)/?$ index.html [L]
Related Topic