Hiding files with apache - apache

I've started using SCSS so in my css folder in my project, I have main.css and main.scss.
Is there any way I can prevent hide main.scss when I put this on my ftp? So it's still there, but not available for direct access?
Thanks!

Put this inside a .htaccess in the directory with the file you want to hide. Rename the file appropriately though (instead of yourfile.css).
<files yourfile.css>
deny from all
</files>
Of course you can also do this in your httpd.conf file aswell but the paths will need to be amended.

The problem with #GhostInTheSecureShell's answer is that this also denies access to the files, so the browser cannot download yourfile.css any more, which is probably not what you wanted.
To hide files (or directories) from index listings, but still allow access to them, use
IndexIgnore yourfile.css
in your .htaccess file.
This also works with patterns, so you can hide all css files using
IndexIgnore *.css
Or just name the files that you want to hide with a certain pattern, so, for example
IndexIgnore hide_me_*
will hide all files or directories that start with hide_me_.

Related

display content of the folder as dir but only for specific folders

I have a generic site in /var/www/ and I did put my webpages in html, including sub folder that I am planning to use to store pdf and doc files.
Now; I would like that when a user go to mysite/files/docs or mysite/files/pdf, they can see the list of files, but even if they click on the parent link on that page, or if they type the url (like mysite/files); they won't see the list.
Is possible to enable the file display feature but only for certain folders? I did check Apache manual and it has options to set in httpd.conf file, although it was not really showing how to turn on or off specific folders; just how to turn it on and off globally.
I have .htaccess files that I use for settings, but even in that case; I can't find a way to display only some folder content and not others.
Create a .htaccess file in each directory files/docs and files/pdf
Then inside each .htaccess file add
Options +Indexes
That's it. It will display the files of only those 2 directories.

Options -Indexes Code in .htaccess

I just wanted to add a simple index.html to www re-direct command in an .htaccess file
When I opened the existing .htaccess file, the 'Options -Indexes' command was already in there. What exactly is this command? What is it instructing the search engines etc. to do?
Not a programmer, just an SEO manager. Thanks much, MB
The Indexes option sets whether you can "browse" the directory or not. If indexes is set to plus, and the directory has no index.html or index.php (of whatever) file, it will show the contents of the directory just like your filemanager would do. So if there are ten images in there, it simply shows them as a list with links to the actual image. You can click them and open them.

Prevent Non-Existent Directories From Loading Wildcard Files

I am looking to prevent URLs for directories that don't exist from loading files with the same basename. For example http://domain.com/test/ is loading test.php. The test directory does not exist, but the file test.php does. I can see how this would be useful in most cases, but I am looking to disable it for my project.
I am on an Apache server. Is there a way to disable this option through an .htaccess file?
If there is an actual name for this type of feature, maybe "wildcard filename helper" or something like that, I'd like to know the official term too. Thanks!
This happens because MultiViews is enabled on the server.
If the apache configuration allows you to do so, you should be able to disable it by putting the following in .htaccess:
Options -MultiViews

Styling and Alternatives to Options +Indexes .htaccess

I'm getting tired of looking at my files.
It seems like there aren't many options to modifying the look of Apache's Options +Indexes .htaccess layout without having root access to the server. It also seems like you can't browse directories and subdirectories safely through 1 PHP file in the root in a similar fashion (for that I would be able to style.)
I have seen tuts on how to change the length of certain outputs, etc, in .htaccess, but perhaps there is a programming language I am not aware of that can emulate the same type of file browsing safely and still be able to take on style properties.
You can use HeaderName HEADER.html and ReadmeName FOOTER.html to create a custom header and footer. You can include some CSS into the header to make the list look a bit more pretty.
Not sure why you would think PHP is not save to use. You indeed need to be careful to not give access to files outside of the specified folder, but that is not very hard to do.
Actually there are plenty of styling options with +Indexes. Not only can you add the header (optionally disabling the autogenerated <html>...<body> tags) and footer, but you can define a stylesheet with IndexStyleSheet cute.css. Using that and some clever selectors, it is possible to create very nice listings. Check the official docs for more details.

How Come Everybody Can See My Private Files?

Sorry for the newbie question...
When I go to http://www.plans4boats.com/scripts/youtubeplayer/ in Google Chrome, I can see a full listing of the files there. What should I do if I don't want any old hacker to just come in and view/copy my source codes? Does it have something to do with htaccess?
I discovered that putting a blank index.html file in the folder helps for THAT folder, but it still leaves all subfolders vulnerable.
What should I google for more information on how to set up my server to prevent this?
Just set Options -Indexes for that particular directories either in an .htaccess file or a <Directory> or <Location> container.
What you need to do is turn of Directory Listing for your specific server. I don't know what server you're using so I can't walk you through it, but just google your server name and how to disable directory listing.
I created a file called .htaccess and put the following contents:
IndexIgnore /