-   Linux - Software (
-   -   Apache (

pave 05-19-2006 01:05 PM


I want to achive the following goal:

If a request is made for any .html file I want server to open index.html. The most important thing is the URL must stay the same so ModRewrite and redirects are out od scope. I kind of achieved it by setting index.html as an 404 error page, but the problem is that all form posted data is lost.

Thank you for you help.

vikasumit 05-20-2006 06:19 AM


Well what you want is achieved by two this ... 404 error page and with mod_rewrite :)
So mod_rewrite is not out of scope..

Let me explain you mod_rewrite here ..

If you request a page say

than what your Web server(apache) does with mod rewrite it will read the url, if it is in form
/[a-zA-Z-].html than it will execute /index.html though the Browser never comes to know that a different page is executed.

If you don't believe me try some Price comparison sites they mostly use mod_Rewrite. and in technical term its URL rewriting..

and for post data well you have to be careful and I am not sure if you can achieve it with 404 page also 404 will not keep this


The most important thing is the URL must stay the same
it willbe achieve by mod_Rewrite module of apache..

pave 05-21-2006 07:15 AM

Thanks for reply. I tried mod_rewrite and it seems that URL in browser does not change so it is what I wanted. The peoblem is that the following rule will perform an infinite number of redirects (loop):

RewriteEngine On
RewriteCond %{REQUEST_URI} /.*\.html
RewriteRule /* /index.html

Any .html url will be redirected to index.html but index.html will also be redirected to index.html and so forth

I tried to create a suitable rule to exclude index.html, with no success. Can you help? Two files should be omitted from the redirect (index.html and admin.html)

vikasumit 05-21-2006 11:58 PM


you rule

RewriteRule /* /index.html
define that any thing after tld is gone to index page which means even a image request will be thrown to index.html page :)

I am not sure as i never try this, but you can do it like this ...


/[^index|admin]*?\.html /index.html
it says if not index or admin and comes infinitely till first period (.) followed by HTML will be gone to index.html
though this will also work with to

What I prefer is you make your pages like this if possible this way you can check this
/pages/(.*)?\.html /index.html

also there are ending directives like L,Q,S,A etc... not sure what they does, but are for rule conditions

Hope that help you

All times are GMT -5. The time now is 10:15 AM.