apache - how to redirect "www.somedomain.com/folder1/demo.jpg" request to some other page using mod_rewrite? -
code block:
options +followsymlinks rewriteengine on rewritecond %{http_host} mysite.000webhostapp.com$ [nc] rewritecond %{http_host} !folder1 rewriterule ^(.jpg)$ http://mysite.00xxxtapp.com/folder1/$1 [r=301,l]
i think want filename in new url well? (not ".jpg")
rewriterule ([^/]+\.jpg)$ http://mysite.00xxxtapp.com/folder1/$1 [r=301,l]
or rewriterule ([^/]+\.jpg)$ /folder1/$1 [l]
if want keep seeing old url
edit
so need more 1 rewriterule.
i suggest steps
- all "fake" urls redirect php script
- all images in /folder1/ must redirected or made inaccessable (suggestion: put them outside document root|)
rewriteengine on # images in somefolder parsed through php script rewriterule somefolder/([^/]+\.jpg)$ /imageshower.php [l]
# redirect no access image
rewriterule folder/*\.jpg /no-access.jpg [r]
the php script able checking 'is user logged in?' or have rights
<?php $filename = basename($_server['request_uri']); // still points jpg if(is_file('folder/'. $filename) && is_allowed($user, $filename)) { header('content-type: images/jpg'); // or other .gif or .pdf etc readfile('folder/'. $filename); } ?>
Comments
Post a Comment