Rewrite based on HTTP_REFERER

#1
Hello

Why doesn't this rewrite work?
The idea is every request to /mypage from these domains, should be redirect to the main URL /.

What is wrong?

Thanks

Code:
context /mypage {
  allowBrowse             1

  rewrite  {
    enable                1
RewriteCond %{HTTP_REFERER} ^https://www.example.com [NC]
RewriteCond %{HTTP_REFERER} ^https://www.example.org [NC]
RewriteRule ^ / [L,R]
  }
  addDefaultCharset       off

  phpIniOverride  {

  }
}
 

Cold-Egg

Administrator
#2
You can use RewriteCond %{REQUEST_URI} to match mypage, and redirect all to the main domain URL in the .htaccess file without using the context.
Code:
RewriteCond %{REQUEST_URI} mypage
RewriteRule .* https:/yourmaindomain
or just redirect mypage to /
Code:
RewriteRule ^mypage/(.*)$ /$1
 
#5
@Cold-Egg I can't get this to work! Do you have any suggestions?

Edit: this is the configuration:

Code:
docRoot                   $VH_ROOT/public
vhDomain                  example.com

context /mypage {
  allowBrowse             1

  rewrite  {
    enable                1
RewriteCond %{HTTP_REFERER} ^https://www.example.org [NC]
RewriteCond %{HTTP_REFERER} ^https://www.example.net [NC]
RewriteRule . / [L,R]
  }
  addDefaultCharset       off
}

context / {
  allowBrowse             1

  rewrite  {
    enable                1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
  }
  addDefaultCharset       off
}
 
Last edited:
#6
ok .. the /mypage context is not working at all!

The solution was adding this to / context:

Code:
RewriteCond %{REQUEST_URI} ^/privacy [NC]
RewriteCond %{HTTP_REFERER} ^https://www.example.org [NC,OR]
RewriteCond %{HTTP_REFERER} ^https://www.example.net [NC]

RewriteRule . / [L,R]
 
Top