2

Suppose the user request for the content such as image in www.example.com/content/img/one.jpg.

If the one.jpg is in the directory img then the image is served. But if the one.jpg is not present then user is redirected one directory up to www.example.com/content/one.jpg.

Whether it has the requested file or not.

It must be valid for all content such as images or documents or videos etc.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ______________________

Thanks

DaOgre
  • 2,080
  • 16
  • 25
Ganesh Pandey
  • 5,216
  • 1
  • 33
  • 39

1 Answers1

1

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?/)?[^/]+/(.+)$ $1$2 [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Actually i want it for all request.. only the last one directory should be redirected to its parent directory if there is not content. I think we are close. Like http://52.74.73.123/img/two.png also need to show the content which is in http://52.74.73.123/two.png – Ganesh Pandey Apr 05 '15 at 06:28
  • But this is not working http://52.74.73.123/img/another/one.gif http://52.74.73.123/img/one.gif [Image is here should have shown] – Ganesh Pandey Apr 05 '15 at 06:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/74501/discussion-between-ganesh-pandey-and-anubhava). – Ganesh Pandey Apr 05 '15 at 06:49