Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making an advertisement blocking DNS server that redirects all the advertisement domains to an instance of Apache. So something like

gets redirected to


However, occasionally I come across links more like

which gets redirected to


which doesn't even exist and hence raises a 404 error.

I was hoping that there would be some way to make Apache serve index.html, regardless of the actual request. Otherwise, if you have an alternate solution that does not involve Apache, I'm up for that too.

share|improve this question
You could have a look at apaches mod_rewrite. Redirecting everything from after the domain to /index.html – rechengehirn Jun 18 '14 at 12:02
This seems like an inefficient way of doing adblocking. – bodhi.zazen Jun 18 '14 at 15:23
@bodhi.zazen How would you do it? Most adblockers work on a similar concept. Block or redirect the requests to the advertising domains. I'll be glad to implement a better alternative if you have one. – sayantankhan Jun 18 '14 at 15:43
To be honest, I use noscript and the default adblock plugins. If that is not sufficient, then you can either use a hosts file (takes work to maintain) or a proxy (privoxy), but again it takes more work to maintain a blacklist yourself. See and , you may need alternates depending on your browser. – bodhi.zazen Jun 18 '14 at 15:50
I'm not maintaining a blacklist myself. I just got off and used dnsmasq to redirect them to my apache server. I used to maintain a hosts file until my sister got an iPad and wanted me to block ads on it. – sayantankhan Jun 18 '14 at 16:56
up vote 10 down vote accepted

In Ubuntu, make sure mod_alias is enabled:

sudo a2enmod alias

Then in your VirtualHost directive you can use AliasMatch.


<VirtualHost *:80>
    DocumentRoot /path/to/your/host
    DirectoryIndex index.html

    AliasMatch ^/(.*)$ /path/to/your/host/index.html

    <Directory "/path/to/your/host">
      Require all granted

Now everything gets redirected to /index.html.

share|improve this answer

You need a rewrite rule in your .htaccess file. Something like the following should work:

RewriteRule ^*$ [R=301,NC,L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.