Rickrolling for 404 requests
Every webserver log is spammed with 404 (Not Found) requests. The setup in this repository allows to redirect such requests to the famous Rickrolling Video.
Idea inspired by this Tweet.
To ease configuration and deployment, Ansible is used and generates a configuration file. The input URLs (the 404) are listed in two files:
- redirect.txt: simple URLs, including the full request, no regexp required
- redirectmatch.txt: complex URLs, a regexp is required to match the URL
The "Redirect" and "RedirectMatch" names are based on the Apache2 mod_alias Module. It is not necessary to enable the more complex mod_rewrite module for simple redirects.
In your vhosts configuration, all you have to do is include the rickrolling.conf:
Include "/etc/apache2/rickrolling.conf"
Two different ways to load the data files into Ansible:
Check out this repository and point your Playbook to the redirect.txt and redirectmatch.txt files.
- name: Read block lists and set config
set_fact:
rickrolling_destination: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
rickrolling_redirect: "{{ lookup('file', '/path/to/ansible-rickrolling/redirect.txt').splitlines() }}"
rickrolling_redirectmatch: "{{ lookup('file', '/path/to/ansible-rickrolling/redirectmatch.txt').splitlines() }}"
- name: Install block list
template:
src: "/path/to/ansible-rickrolling/apache2.conf"
dest: "/etc/apache2/rickrolling.conf"
owner: www-data
group: www-data
mode: 0755
notify:
- restart apache2
Use the URI module to download a copy of the files during deployment.
Note: Your Ansible host must be able to reach GitHub during deployment.
- name: Fetch redirect.txt
uri:
url: https://raw.githubusercontent.com/andreasscherbaum/ansible-rickrolling/master/redirect.txt
return_content: yes
register: rickrolling_src_redirect
- name: Fetch redirect.txt
uri:
url: https://raw.githubusercontent.com/andreasscherbaum/ansible-rickrolling/master/redirectmatch.txt
return_content: yes
register: rickrolling_src_redirectmatch
- name: Import block lists and set config
set_fact:
rickrolling_destination: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
rickrolling_redirect: "{{ rickrolling_src_redirect.content.splitlines() }}"
rickrolling_redirectmatch: "{{ rickrolling_src_redirectmatch.content.splitlines() }}"
- name: Install block list
template:
src: "/path/to/ansible-rickrolling/apache2.conf"
dest: "/etc/apache2/rickrolling.conf"
owner: www-data
group: www-data
mode: 0755
notify:
- restart apache2
You can send PRs with additional URLs, or config examples for other webservers.