[RESOLVED] Redirecting all HTTP requests to one file [Apache]
I guess there is no right forum section for this Q, but if you think there is a better section Pena, feel free to move it.
I'd like to redirect all the HTTP requests of my Apache server to one single file so I can handle them exactly like I want. My first thought was to make the 404 page hangle all requests, but I am affraid it will both be slow (is it?) and maybe even send out a 404 before redirecting??
So my second thought came along when I saw mod_rewrite was installed on the server. Would it be feasible (or at all possible) to use mod_rewrite to direct all HTTP requests to the same file index.foo by using mod_rewrite?
- ØØ -
Re: Redirecting all HTTP requests to one file [Apache]
The ErrorDocument directive does not suppress the HTTP error code, so yes, it would send a 404 code.
You can use mod_rewrite to do what you want by matching every request:
Code:
RewriteEngine on
RewriteRule ^(.*)$ index.foo [R=301,L]
In your index.foo script, the REQUEST_URI server variable will contain the original URI requested, so you can parse that as you wish.
Re: Redirecting all HTTP requests to one file [Apache]
After some sweat and tears I got it working as it should. At the moment the file structure looks like this:
Code:
.
..
root.htm
root.py
/functions/.
/functions/..
/functions/functions.html
And as you can see, no matter what HTML file you try to get to right now, you will end up triggering root.py.
Examples:
http://www.userjs.noteme.com/root.html
http://www.userjs.noteme.com/functions/functions.html
http://www.userjs.noteme.com/penagate/cheersm8te.html
But non html links will still look for a file:
http://www.userjs.noteme.com/root.htm
So I guess I am happy, cheers,
- ØØ -