10 Replies - 372 Views - Last Post: 07 July 2017 - 10:19 AM

#1 Splashsky  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 282
  • Joined: 25-August 13

Serving/Accessing Non-Public Assets

Posted 05 July 2017 - 07:47 PM

I've never worked with web administration before. This stuff goes over my head. *insert Peanut gif here*
I have a web app project on a local virtual host using the Mac application MAMP. My file directory looks like the following...
Posted Image
And I can't get the CSS file in /web to recognize the images in /assets/images, even though my PHP scripts can see the templates (and I know about PHP not caring about directory visibility and such) and I was wondering what steps I could take to serve images from /assets from the index.php without creating a php script just for returning images.

Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: Serving/Accessing Non-Public Assets

#2 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6538
  • View blog
  • Posts: 30,610
  • Joined: 10-May 07

Re: Serving/Accessing Non-Public Assets

Posted 06 July 2017 - 05:58 AM

I would first check the server logs. It should be logging errors with what it can't reach when attempted. My suspicion is directory permissions.
Was This Post Helpful? 0
  • +
  • -

#3 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1769
  • View blog
  • Posts: 5,640
  • Joined: 15-January 14

Re: Serving/Accessing Non-Public Assets

Posted 06 July 2017 - 10:13 AM

If web is your web directory root, so that nothing above or on the same level is accessible from the browser, then other than a server-side script like PHP to send the headers and file data for that stuff you could create a symbolic link to that directory from web. So you can create a symbolic link in the web directory called images and point it to /assets/images, so that any requests to the images directory go to that other directory. The web server will still need permission to read those files though.
Was This Post Helpful? 0
  • +
  • -

#4 Splashsky  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 282
  • Joined: 25-August 13

Re: Serving/Accessing Non-Public Assets

Posted 06 July 2017 - 05:49 PM

I've been scouring the net, but I can't find anywhere that explains how to enforce a symlink in an .htaccess file. Is that something I would put in an .htaccess file? Would it be better to simply process a request for an image through my webroot? I'm not at all sure how to accomplish this programmatically.

All requests to /web/ and index.php in particular are rewritten in my htaccess file to look.like/this/in/practice, which is parsed and process through the index.php file and related classes. I could do a uri.for/images/there.gif, but I was hoping there was a way to avoid having to send such requests through PHP.

This post has been edited by iLiTH: 06 July 2017 - 05:55 PM

Was This Post Helpful? 0
  • +
  • -

#5 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1769
  • View blog
  • Posts: 5,640
  • Joined: 15-January 14

Re: Serving/Accessing Non-Public Assets

Posted 06 July 2017 - 06:25 PM

Quote

I've been scouring the net, but I can't find anywhere that explains how to enforce a symlink in an .htaccess file.

There's a good reason for that.

Quote

Is that something I would put in an .htaccess file?

No. I don't know if there's another way, but I create symlinks in the command prompt using ln -s.

Quote

I could do a uri.for/images/there.gif, but I was hoping there was a way to avoid having to send such requests through PHP.

Your htaccess rules shouldn't apply if the web server gets a request for a file that actually exists, it would only redirect requests for files that don't exist. I'm pretty sure it will still work that way even if you're requesting a file in a symlink.

Another option is to edit the Apache config to set up a virtual path to the assets or images folder.

If none of those are possible, then it sounds like funneling all requests through a PHP script is your only option. Make sure you do correct validation to verify that they are requesting a file from that specific directory, get the real path of the file and verify its location. That's the least best solution though because you're giving up everything that the web server can do, like caching and partial content serving, so hopefully you have a good reason for keeping things like images out of the web root.
Was This Post Helpful? 0
  • +
  • -

#6 Splashsky  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 282
  • Joined: 25-August 13

Re: Serving/Accessing Non-Public Assets

Posted 06 July 2017 - 06:29 PM

View PostArtificialSoldier, on 06 July 2017 - 06:25 PM, said:

That's the least best solution though because you're giving up everything that the web server can do, like caching and partial content serving, so hopefully you have a good reason for keeping things like images out of the web root.

Is it better to just put images into the web root, then?
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6538
  • View blog
  • Posts: 30,610
  • Joined: 10-May 07

Re: Serving/Accessing Non-Public Assets

Posted 06 July 2017 - 07:35 PM

A symbolic link will look like just a directory to the .htaccess file, or the webserver.

Have you checked your weblogs? If not, you're only guessing.

View Postno2pencil, on 06 July 2017 - 08:58 AM, said:

My suspicion is directory permissions.


View PostArtificialSoldier, on 06 July 2017 - 01:13 PM, said:

The web server will still need permission to read those files though.

Was This Post Helpful? 0
  • +
  • -

#8 Splashsky  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 282
  • Joined: 25-August 13

Re: Serving/Accessing Non-Public Assets

Posted 06 July 2017 - 07:52 PM

Okay, so in my http.conf I have this block
Alias /assets/ "/Documents/Websites/WorldOfSeven/assets/"
<Directory "/Documents/Websites/WorldOfSeven/assets/">
	Options Indexes MultiViews
	AllowOverride None
	<IfModule authz_host_module>
		Order allow,deny
		Allow from all
	</IfModule>
</Directory>



and in my apache error log I have this line...
[error] [client ::1] File does not exist: /Documents, referer: http://localhost/user/register



Which tells me I probably just don't know how my file system works necessarily within my virtual host. I'll do more reading on that.

But as it were, is there any advantage to keeping images outside the public directory?

ALSO; I was thinking, idk if permissions are an issue but I don't see that being the case on my laptop :P

This post has been edited by iLiTH: 06 July 2017 - 07:52 PM

Was This Post Helpful? 0
  • +
  • -

#9 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6538
  • View blog
  • Posts: 30,610
  • Joined: 10-May 07

Re: Serving/Accessing Non-Public Assets

Posted 06 July 2017 - 11:13 PM

View PostiLiTH, on 06 July 2017 - 10:52 PM, said:

and in my apache error log I have this line...
[error] [client ::1] File does not exist: /Documents, referer: http://localhost/user/register


Can you show how this is referenced via the html code? If you have php, can you somehow force an echo of "pwd" (present working directory).


View PostiLiTH, on 06 July 2017 - 10:52 PM, said:

ALSO; I was thinking, idk if permissions are an issue but I don't see that being the case on my laptop :P

You have to remember that your Desktop is owned by you, & the service is likely running as a MAMP specific user.
Was This Post Helpful? 0
  • +
  • -

#10 Splashsky  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 282
  • Joined: 25-August 13

Re: Serving/Accessing Non-Public Assets

Posted 07 July 2017 - 04:46 AM

This is the only code I know of that tries to pull from the /assets directory (aside from PHP code, which works fine)
/* main.scss */
section#register {
    min-height: 100vh;
    width: 100%;
    background-image: url('/assets/images/awesome2.jpg');
    background-size: cover;
    background-position: center center;
}


And the reason it's not showing is because it requests the image from localhost/assets/images/awesome2.jpg, which of course is invalid.

This post has been edited by iLiTH: 07 July 2017 - 04:46 AM

Was This Post Helpful? 0
  • +
  • -

#11 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1769
  • View blog
  • Posts: 5,640
  • Joined: 15-January 14

Re: Serving/Accessing Non-Public Assets

Posted 07 July 2017 - 10:19 AM

Quote

But as it were, is there any advantage to keeping images outside the public directory?

The only case for storing things outside of the public directory is if you need to control access, and even then there are still ways to control access if they're under the public directory somewhere.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1