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

  1. all "fake" urls redirect php script
  2. 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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -