?
Solved

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

Posted on 2009-12-30
10
Medium Priority
?
298 Views
Last Modified: 2013-11-30
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
0
Comment
Question by:TomEA
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 26151508
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

0
 
LVL 83

Expert Comment

by:leakim971
ID: 26151511
0
 
LVL 1

Author Comment

by:TomEA
ID: 26151656
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
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 83

Expert Comment

by:leakim971
ID: 26151675
0
 
LVL 1

Author Comment

by:TomEA
ID: 26151741
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.
0
 
LVL 1

Author Comment

by:TomEA
ID: 26151742
By default directory, I mean /var/www, where index.html lives.
0
 
LVL 4

Accepted Solution

by:
Rajeshpola earned 1000 total points
ID: 26151995
Hi ..

You can use RedirectMatch to accomplish, you need to change the settings in httpd.conf file,

put the below peace of configuration.
RedirectMatch ^/$ http://www.sample.com/index.html 

the above line shoud send all the req from web server to that page, make sure that you remove .htaccess file before trying this as the apache is having priority.  

Let me know if u need further information.
0
 
LVL 1

Author Comment

by:TomEA
ID: 26182654
Where in the Apache configuration should that RedirectMatch line go?
0
 
LVL 3

Expert Comment

by:shairozan
ID: 26183665
You can add it before the last </virtual host> tag in your /etc/apache2/sites-enabled/000-default file
0
 
LVL 4

Expert Comment

by:Rajeshpola
ID: 26187787
If you a virtual host you can add it der else you can add it at the end of httpd.conf file.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
How to fix a SonicWall Gateway Anti-Virus firewall blocking automatic updates to apps like Windows, Adobe, Symantec, etc.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question