Reputation: 195
This is my htaccess code in a certain folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule (.*) ./index.php?id=$1 [L]
</IfModule>
How can I make this so this happens IF the HTTP_REFERER is my own site, but if it's not, then redirect to a certain file?
I've been trying something like this, but it doesn't work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://.*MYSITE.*$ [NC]
RewriteRule ^index\.php$ - [L]
RewriteRule (.*) ./index.php?id=$1 [L]
RewriteCond %{HTTP_REFERER} !^http://.*MYSITE.*$ [NC]
RedirectMatch 301 ^(.*)$ MYFILE.jpg
</IfModule>
I've already gone through several posts on this topic but nothing worked the way I want it. Thanks
Upvotes: 0
Views: 64
Reputation: 41219
You can use this :
RewriteEngine on
#if http_referer is not my site then redirect the request
RewriteCond %{HTTP_REFERER} !mysite\.com [NC]
RewriteCond %{REQUEST_URI} !/thispage\.php [NC]
RewriteRule (.*) http://example.com/thispage.php [L,R=301]
#rules for mysite.com
RewriteRule ^index\.php$ - [L]
RewriteRule (.*) ./index.php?id=$1 [L]
Upvotes: 1