Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

www.addomain.com

gets redirected to

dnsserver.localnetwork

However, occasionally I come across links more like

www.addomain.com/some_ad

which gets redirected to

dnsserver.localnetwork/some_ad

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
1  
You could have a look at apaches mod_rewrite. Redirecting everything from after the domain to /index.html –  rechengehirn Jun 18 at 12:02
    
This seems like an inefficient way of doing adblocking. –  bodhi.zazen Jun 18 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. –  Bolt64 Jun 18 at 15:43
1  
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 addons.mozilla.org/en-US/firefox/addon/noscript and addons.mozilla.org/en-US/firefox/addon/adblock-plus , you may need alternates depending on your browser. –  bodhi.zazen Jun 18 at 15:50
    
I'm not maintaining a blacklist myself. I just got off pgl.yoyo.org/adservers 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. –  Bolt64 Jun 18 at 16:56

2 Answers 2

up vote 7 down vote accepted

In Ubuntu, make sure mod_alias is enabled:

sudo a2enmod alias

Then in your VirtualHost directive you can use AliasMatch.

Example:

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

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

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

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 ^*$  http://www.addomain.com/index.html [R=301,NC,L]
share|improve this answer

Your Answer

 
discard

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.