diff --git a/debian/scripts/koha-plack b/debian/scripts/koha-plack
index c0da9d1..db9aa43 100755
--- a/debian/scripts/koha-plack
+++ b/debian/scripts/koha-plack
@@ -144,9 +144,9 @@ enable_plack()
     local instancefile=$(get_apache_config_for "$instancename")
 
     if ! is_plack_enabled $instancename; then
-        # Uncomment the plack related lines for OPAC and intranet
-        sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-opac-plack.conf\)$:\1:' "$instancefile"
-        sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-intranet-plack.conf\)$:\1:' "$instancefile"
+        # Define the instance name and add the plack related lines for OPAC and intranet
+        sed -i "s:^\(\s*\)\(Include /etc/koha/apache-shared-opac.conf\):\1\2\n# Generated by koha-plack script -- add plack-related stuff\n\1Define instance $instancename\n\1Include /etc/koha/apache-shared-opac-plack.conf:" "$instancefile"
+        sed -i "s:^\(\s*\)\(Include /etc/koha/apache-shared-intranet.conf\):\1\2\n# Generated by koha-plack script -- add plack-related stuff\n\1Define instance $instancename\n\1Include /etc/koha/apache-shared-intranet-plack.conf:" "$instancefile"
         [ "${quiet}" != "yes" ] && warn "Plack enabled for ${instancename}"
         return 0
     else
@@ -161,7 +161,11 @@ disable_plack()
     local instancefile=$(get_apache_config_for "$instancename")
 
     if is_plack_enabled $instancename; then
+        # Remove the plack related lines for OPAC and intranet
+        perl -0777 -i -pe "s:# Generated by koha-plack script -- add plack-related stuff\n\s*Define instance $instancename\n\s*Include /etc/koha/apache-shared-opac-plack.conf::" "$instancefile"
+        perl -0777 -i -pe "s:# Generated by koha-plack script -- add plack-related stuff\n\s*Define instance $instancename\n\s*Include /etc/koha/apache-shared-intranet-plack.conf::" "$instancefile"
         # Comment out the plack related lines for OPAC and intranet
+        # (keep these lines in case plack was enabled with the previous method)
         sed -i 's:^\(\s*Include /etc/koha/apache-shared-opac-plack.conf\)$:#\1:' "$instancefile"
         sed -i 's:^\(\s*Include /etc/koha/apache-shared-intranet-plack.conf\)$:#\1:' "$instancefile"
         [ "${quiet}" != "yes" ] && warn "Plack disabled for ${instancename}"