I’m trying to create an .htaccess mod_rewrite that will behave differently if the current referer isn’t my own domain. For instance, say I own example.com (i.e. http://www.example.com, http://example.com, etc). When somebody goes to example.com (or an subdomain such as beta.example.com), I want to ignore this .htaccess rule. So I guess the regex would basically just look for example.com somewhere in it and ignore those.
However, is a domain such as otherdomain.com (which is assumed to point to example.com via cname or A-record) access my site, I want to redirect them somewhere. Here’s what I have so far that I believe is close but isn’t working.
My main confusion with these rules is the part that comes after the RewriteRule (^$ in this case). I’ve seen a few different things put there in my Googling and I’m not sure on the differences. For instance, I’ve also seen just a ^, a (.*)$, etc.
RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)*(example)\.com
RewriteRule ^$ redirectfile.php [L]
I’ve also been messing with
RewriteCond %{HTTP_REFERER} ^http://(.+\.)*\.com
RewriteCond %1 !^(example)\.$
RewriteRule ^$ redirectfile.php [R=302,L]
Try
You had
^$, which would only match the home page.I changed it to just
^which will match every request, assuming that you want to match every request.A
(.*)$would also match every request, but also capture the match so that you reuse in in the target as $1