Hello,
I want to block and redirect website example from 1PM to 2PM
I want to block website1.com and redirect to website2.com
Thank you
<?php
if (preg_match('/^([^\n\.]+\.)*website1\.com$/i', $_SERVER['HTTP_HOST'])) {
header('Location: http://website2.com');
}
/ip firewall layer7-protocol add="HTTP website1.com" regexp="^\S+ \S+ HTTP\/\d\.\d[^H]+Host: ([^\n\.]+\.)*website1\.com.+\n\n"
/ip firewall nat add comment="Redirect for website1.com" chain="dstnat" layer7-protocol="HTTP website1.com" time="13h-14h,sun,mon,tue,wed,thu,fri,sat" action="dst-nat" to-addresses="192.168.0.254"
/ip firewall layer7-protocol add name="HTTP website1.com" regexp="^\S+ \S+ HTTP\/\d\.\d[^H]+Host: ([^\n\.]+\.)*website1\.com.+\n\n"
Opps. I missed the name argument. The first command should beThe second commands needs the first before it can work.Code: Select all/ip firewall layer7-protocol add name="HTTP website1.com" regexp="^\S+ \S+ HTTP\/\d\.\d[^H]+Host: ([^\n\.]+\.)*website1\.com.+\n\n"
^\S+ \S+ HTTP\/\d\.\d[^H]+Host: ([^\n\.]+\.)*website1\.com.+\n\n
HTTP website1.com
^\S+ \S+ HTTP\/\d\.\d.+Host\:([^\n\.]+\.)*website1\.com.*\n\n
You'd have to do a dst-nat to a web server that you control, and from there, based on the hostname, redirect to the desired site.
To do the redirect, with PHP at least, it's as simple asThe most difficult part is matching the requests that should be redirected to the web server in the first place. The easiest (although somewhat error prone and inefficient) way is to use layer7-protocol filter. Something like:Code: Select all<?php if (preg_match('/^([^\n\.]+\.)*website1\.com$/i', $_SERVER['HTTP_HOST'])) { header('Location: http://website2.com'); }
Once you have that, adding the dns-nat rule is trivial:Code: Select all/ip firewall layer7-protocol add="HTTP website1.com" regexp="^\S+ \S+ HTTP\/\d\.\d[^H]+Host: ([^\n\.]+\.)*website1\.com.+\n\n"
(replace 192.168.0.254 with the IP of your web server)Code: Select all/ip firewall nat add comment="Redirect for website1.com" chain="dstnat" layer7-protocol="HTTP website1.com" time="13h-14h,sun,mon,tue,wed,thu,fri,sat" action="dst-nat" to-addresses="192.168.0.254"
P.S. The regex in the PHP, and the equivalent portion in the layer7-protocol both ensure you redirect website1.com as well as all of its subdomains.