Access Denied on image styles images with private file system - .htaccess

Image upload is private. Images are being accessed through /system/files/ path. But on accessing the private images with image styles in /system/files/styles/ path I'm getting access denied.
I have tried this solution, but it did not work. Please share if there is any other way.
RewriteCond %{REQUEST_URI} ^/sites/.*/files/private/styles/
RewriteRule ^/core/authorize.php/core/authorize.php(.*)$ /core/authorize.php$1

Related

Image is not retrieve using url

I have an android app where i want to display image which i have uploaded in server.But i am not able to do so ,as my server side have .htaccess file where i am redirecting all my method request to .php page . and the folder where the image is save is also there in that folder , where .htaccess file exists .
In my android app i am displaying image using Picasso library ,so whenever i put url of image it gives me error like access denied or file not found . but,images are present in upload_folder.
This is my .htaccess file
RewriteEngine on
RewriteRule ^.+$ sample.php [L]
This my server-side directory structure :
- root
- upload_folder
- img1.jpg
- img2.jpg
- .htaccess
- myphpfile.php
Also i am accessing my .php page in this way
http://example.com/root/getall_rentalpackages/?apiKey=eyJhbGciOiJIUzUxMiIsInXVC
So whenever i request for image like below it doesn't retrieve image.
http://example.com/root/upload_folder/img1.jpg
How can i display image using url and what changes i need to make in .htaccess file whenever image request is there ? I don't know much about .htaccess please help me .Thank you

images,js, css not loaded when using htaccess

First what I want to note it for you is
I use appserv.
I create the .htaccess file in direct file, so .htaccess file is in the folder /web.
All I want is use RewriteRule for all web links except (.css)-(.js)-(all types of images and .txt)-(and all files name).
I use this code:
RewriteEngine On
RewriteRule ^content/([0-9]+)/$ content.php?pid=$1 [L]
but when I open this page as web/content/2, the css, js, images are not loaded.
I do not know what's the problem :(

Refer to subfolder in .htaccess

I'm trying to use Stacey CMS in conjunction with retina.js for my small portfolio site. Stacey tells all images inside a project folder to be added to the page. At the same time I'd like to serve #2x hi-dpi images. If I include these in the same folder, Stacey will add both the regular image.png and image#2x.png to the page, which I want to avoid.
To solve this, I want to rewrite all images ending with #2x to have the root /retina inside the same project folder. This folder is dynamic, ie. there are many different project folders, so I would like to have one rewrite rule to work for all.
I've gotten to this point with some help from a fellow stack overflow user:
RewriteRule ^(.*)#2x(.*)$ /Retina/$1#2x$2 [L]
This however, does not refer to a subfolder of the original project folder. How do I go about referring to the correct folder?
Edit: Alternatively there may be other ways to solve this issue? Changing retina.js retina image path
I think that the problem you encounter is do to an endless redirect loop.
as your rule
RewriteRule ^(.*)#2x(.*)$ /Retina/$1#2x$2 [L]
Will try to redirect the call for the retina image uri like /image#2x.jpg but also again and again for the new url's /retina/image#2x.jpg as your rule only checks if the requested uri has the #2x string in it.
Try adding another condition to the rule that will prevent the rule to be processed for images that are in the retina folder
RewriteCond %{REQUEST_URI} !Retina
RewriteRule ^(.*)#2x(.*)$ /Retina/$1#2x$2 [L]
If the Retina folder is actually inside another folder and you have multiple Retina folders, meaning that when you call site.com/project1/image.png the retina version is in site.com/project1/retina/image#2x.png then you should try this:
RewriteCond %{REQUEST_URI} !Retina
RewriteRule ^(.*)/(.*)#2x(.*)$ /$1/Retina/$2#2x$3 [L]
in the Retina folders are inside the sub-folders, the first rewrite rule we used will have both the folder name & the image name in the variable $1, so what we should do is just break the folder name & the image name into two separate variables

htaccess to fix broken links on local site

So after moving a live site onto a local computer for offline show casing, a lot of the links have broken because of missplaced ../ that dreamweaver puts in.
It works online because the user of that domain doesn't have permission to leave it's doc root, but not so locally.
Is there an .htaccess that I could put the root dir that would restrict or redirect back to itself when trying to navigate to it's parent?
So the site is in xampp/mysite/ and an img src has a value of ../images/image.png
So it's looking for the image at xampp/images/image.png instead of staying in it's root dir of xampp/mysite/images/image.png
I am assuming that all of your images are in the /xampp/mysite/images directory.
If so, then you could try adding the following to your .htaccess file in the root directory of your site.
RewriteEngine on
RewriteBase /
#if request is not in xampp/mysite/images/
RewriteCond %{REQUEST_URI} !^/xampp/mysite/images/ [NC]
#rewrite images to /xampp/mysite/images
RewriteRule /(.+\\.(png|jpg|gif))$ /xampp/mysite/images/$1 [NC,L]

404 Image Placeholder

I've got a product gallery I'm working on and just did an import. This added a bunch of references to images that don't exist on the server.
Right now when the image tries to load, it's got that broken image icon, which is ugly, and well, should be handled better.
Ideally, whenever a broken image would be displayed -- that is to say when an image's path just doesn't exist -- I would like Apache to show a placeholder image instead.
Is there any way to do this via .htaccess?
Use RewriteCond with -f to check if the file exists, e.g.:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*(\.gif|\.jpe?g|\.png)$ placeholder.jpg [L]

Resources