0

I am trying to hide the real path of the image, but not getting any proper solution. I have added some lines in .htaccess but its not working, I have added :

RewriteEngine On
RewriteRule ^ewallet\/public\/frontend\/img\/(.*)$ /ewallet/public/frontend/images/$1 [L]

Please help me out, Thanks in advance.

Anisur Rahman
  • 644
  • 1
  • 4
  • 17
Bhawesh
  • 3
  • 4
  • What stack are you using for frontend. – Hassaan Ali Feb 07 '22 at 05:13
  • if you're working on a cloud hosting provider you can use `{{ mix('foo/foobar.png')}}` – Hassaan Ali Feb 07 '22 at 05:14
  • I am using WHM shared hosting – Bhawesh Feb 07 '22 at 05:15
  • You can still use node modules on a WHM shared hosting. They usually allow node modules, I've worked with node 14.x.x on namecheap steller hosting. – Hassaan Ali Feb 07 '22 at 05:19
  • 2
    What's the point of all this work? A client can see the image and its path, the image can be saved or copied when ever it's loaded to a browser. – Teemu Feb 07 '22 at 05:26
  • @Teemu I just want to hide the path of image. – Bhawesh Feb 07 '22 at 05:32
  • @HassaanAli I tried, but it still showing the full path of url. – Bhawesh Feb 07 '22 at 05:32
  • 1
    You can't hide the path of images in a browser. Everything what is loaded is public, including image paths. – Teemu Feb 07 '22 at 05:33
  • Assuming /ewallet/public/ is your web root for example.com: Try creating an .htaccess file at the location `/ewallet/public/.htaccess`. For line 1 use `RewriteEngine On` for line 2 use `RewriteRule ^/?frontend/img/(.+)$ /frontend/images/$1 [END]` this means ppl can visit your site at example.com/frontend/img/some-image.png and it will render, provided it exists physically at `/ewallet/public/frontend/images/some-image.png` – Kevin Y Feb 07 '22 at 05:54
  • @KevinY Nothing happens, – Bhawesh Feb 07 '22 at 06:06
  • What if you make a syntax error within the .htaccess file? Double check it is being read and properly causes a 500 error. If not, you might need to enable allowoverride so it actually reads the .htaccess file: https://stackoverflow.com/questions/18740419/how-to-set-allowoverride-all – Kevin Y Feb 07 '22 at 06:08
  • @kevinY My image url is https://sandbox.example.com/public/image/test/test1.png and I have created the .htaccess file inside /home/example/public_html/sandbox/public/.htaccess and applied same lines in it as you said – Bhawesh Feb 07 '22 at 06:11
  • I have added, RewriteEngine On RewriteRule ^/?image/img/(.+)$ /image/test/$1 [END] on .htaccess file – Bhawesh Feb 07 '22 at 06:15
  • I wasn't aware you wanted "public" as a folder visible to the web. Delete that .htaccess file and move it to here: /home/example/public_html/sandbox/.htaccess then use: line 1: `RewriteEngine On` line 2: `RewriteRule ^/?public/image/img/(.+)$ /public/image/test/$1 [END]` Bear in mind an .htaccess file might already exist there if you're using cpanel. But note that generally, with laravel, public should not be a directory visible to the web, You probably have laravel configured wrong. Files like README.md and .env, and composer.json should not be visible to the web. – Kevin Y Feb 07 '22 at 06:24
  • See how to set up laravel within a subdomain on cpanel: https://stackoverflow.com/questions/39886926/how-to-upload-laravel-project-on-subdomain you'll notice there that the document root includes the public directory like so in the answer there: `public_html/registration/public/`. In your case , this should be the document root: `/home/example/public_html/sandbox/public/` but bear in mind running laravel on a subdomain through cpanel like this is really bad since the root domain can still see the subdomain as a subdirectory and still gain access to below web root things like .env – Kevin Y Feb 07 '22 at 06:34
  • it worked for me thankyou, i tried https://sandbox.example.com/fakepath/test.png. But, can I do the same for multiple image paths ? – Bhawesh Feb 07 '22 at 06:39
  • It could.... But I'd probably focus on improving the security. Instead of having a subdomain like `/home/example/public_html/sandbox/public/` which could be accessed as example.com/sandbox and gain access to a file .env or composer.json, I'd move it away from the root domain. Something like this would be the ideal structure for laravel on a subdomain: `/home/example/subdomains/sandbox/public/` and in this way you're not exposing a public_html to the root domain like example.com where duplicate content would exist where stuff below root for the subdomain would be within reach of the root domain – Kevin Y Feb 07 '22 at 06:43

0 Answers0