[eluser]John_Betong_002[/eluser]
Nearly there but cannot get both conditions to work together.
What I would like to do is to somehow trap the external URL before it fails the routing tests, etc.
The following .htaccess in the images folder is supposed to:
1. accept image links from my own site
2. intercept all external links and divert to an ./images/index.php
(where URL is parsed and routed to a search routine).
.htacees
Code:
RewriteEngine on
# this line redirects everything to index.php including links from my own site
# RewriteRule (.*) index.php
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?johns-jokes.com [NC]
# RewriteRule \.$ ./index.php
# RewriteRule (.*) index.php/$1 [R,NC,L]
./images/index.php
Code:
<?php
// this works fine
// 1. parses the URI
// 2. formats the results
// 3. redirects the results to my search routine with parameters
$x = $_SERVER['REQUEST_URI'];
if(strpos($x, '.'))
{
// bad link used for testing
// $x = http://johns-jokes.com//afiles/images/days-before-christmas.png" width="39" alt="image"/>
$x=substr($x,15);
$i2=strpos($x, '.');
$x=substr($x, 0, $i2);
$x=str_replace('-','/', $x);
header ('HTTP/1.1 301 Moved Permanently');
header('Location: http://johns-jokes.com/joke/search/' .$x, TRUE, 301);
exit;
}