Link to home
Start Free TrialLog in
Avatar of TomEA
TomEA

asked on

How can I get Apache to serve a generic page for any URL entered?

Hello!

I have an Apache 2.2 web server running on Ubuntu 9.10 server. I need to configure it so that any URL that is given to it will be responded to with the same generic page. In other words, say our domain is sample.com, I would need it to respond to URL's such as:

http://www.sample.com/page.html
http://www.sample.com/whatever/page.cfm?stuff=yes
http://www.sample.com/another/page/index.php

But I would need it to respond to all of those by going to the same generic page. The purpose here is to create a downtime notice that will be displayed regardless of the link that the user has clicked on.

Can anyone tell me what I'd have to put in the conf file to accomplish that?

Thanks!

- Tom
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Hello TomEA,

With an .htaccess :

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

Open in new window

Avatar of TomEA
TomEA

ASKER

Thanks!

That looks like the solution. However, it appears that the rewrite module is not currently enabled. I'm used to dealing with Apache on Windows, not Linux, and am not sure how to enable it. Modules don't seem to be loaded from the apache2.conf file on this version.

Any pointers?

Thanks!

- Tom
Avatar of TomEA

ASKER

I have verified that the rewrite module is loading successfully, and I've copied and pasted the rewrite code exactly (except for changing the URL) to an .htaccess file in the server's default directory. But everything is still coming up with a 404 Not Found error. Not sure what I'm doing wrong.
Avatar of TomEA

ASKER

By default directory, I mean /var/www, where index.html lives.
ASKER CERTIFIED SOLUTION
Avatar of Rajeshpola
Rajeshpola

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TomEA

ASKER

Where in the Apache configuration should that RedirectMatch line go?
You can add it before the last </virtual host> tag in your /etc/apache2/sites-enabled/000-default file
If you a virtual host you can add it der else you can add it at the end of httpd.conf file.