apachemod-rewritehttp-status-code-404

Apache config to direct all requests to the same page


I am creating a custom web server that is designed to serve a single page, regardless of the request URL:

 - www.example.com/
 - www.example.com/spam/eggs/spam/?ID=eggs
 - foo.example.com/
 - ...

I am using a wildcard DNS record entry to handle the subdomains, but I'm wondering the best way to handle the page requests.

My first thought was simply to have no pages on the site and create a custom 404 page, which was the page I wanted to serve, but I thought that losing an error page might have problems in the future, not to mention sending a 404 error to the client might have effects I am not aware of. Should I be using mod_rewrite instead?

How would you do this? 404, mod_rewrite, or?


Solution

  • I'll use this as an answer

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /index.php/$1 [L]
    </IfModule>
    <IfModule !mod_rewrite.c>
        ErrorDocument 404 /index.php
    </IfModule>