Why does .htaccess automatically changes to .htaccess.txt - php

I am trying to use mod_rewrite and appache to convert my dynamic URLs in to static ones. Therefore I created a .htaccess file in my root folder that is c:xampp/htdocs/unnamed. However whenever i try to rename my text document to .htaccess it automatically changes to .htaccess.txt. It appears only .htaccess in the folder but when i look in the details in the properties menue it is actually .htaccess.txt. Does anyone know how do i change it to just .htaccess

That is because on windows it thinks .htaccess is the name of the file. It considers it to be text. Linux it works differently. It doesn't depend on extensions in Linux.
In order for it to work you just rename the file and remove .txt from it. Then it should work how you like it.
Open the file your created in a text editor, just use Notepad.
Choose "Save as.." and select "All types (.)" next to file type.
Then type .htaccess and click on save.
FYI: I would also turn on showing file extensions if you don't already have that on so you can see what extensions your files have by looking at them in the folder.
http://windows.microsoft.com/en-us/windows/show-hide-file-name-extensions#show-hide-file-name-extensions=windows-7

This is because Windows default setting doesn't show the known file extension. You can change that option in the Folder option dialog.
But for easier, just open the command line and rename it by command:
ren .htaccess.txt .htaccess
Next time when saving a file, paying attention to the file extension, especially not to save source code as .txt file :).

Related

Hide a folders content but leave the files accessible

A script on my website uploads images to mysite.com/uploads and generates a path to the image uploaded like mysite.com/uploads/123456789.jpg.
The image should only to visible to users with a path to the file. The folder shouldn't list out its contents.
The script is built using PHP and runs on a Linux system (CentOS) managed by cPanel. I am new to Linux and I don't understand how this can be done and I need your help with it.
I beleive that's not PHP issue. If you using Apache webserver you need a .htaccess file in that folder with the following content:
Options -Indexes
And also you can try simply add empty file index.html in each directory you'd like to hide.

What are possible reasons that HTML download link is failing?

I created a page for users to download certain files. I used the HTML download link to do this as so:
<a download href="/home/Uploads/someDir/someFile.PNG" >View</a>
This worked fine when I was developing on my laptop with WAMP. When I uploaded the code to our Centos 7 Server it did not work. I changed the Uploads, someDir, and someFile.PNG permissions to 777. I also made sure that the file path was correct. But the when the download link is pressed the file icon at the bottom of the screen says "Failed no file".
Maybe I need to do more with the permissions. I know that the folder that the html file is in has restricted permissions, but I would prefer to keep them that way. I do not know how that could cause an issue.
I am looking for debugging tips/possible causes. At this point I am clueless where to look.
The issue with the download not working is simply due to the fact that the path to your file is wrong. My advice on your root directory which is in most cases is var/www/html, create a folder called say somefoldername and manually upload the file to that folder then change the download link to be
View.
"Failed no file" has nothing to do with permissions. The path to your download file has most likely changed when the files were uploaded to the server. You should manually check to see if the file at
/home/Uploads/someDir/someFile.PNG
actually exists. If not you can change the link accordingly or move the download file to the appropriate location.
Another good alternative to solve this error is to put a dot '.' at the beginning of the url:
<a download href="./someDir/someFile.PNG" >View</a>
This way you will not need to indicate the complete url.
And if in the future the url changes, you won't have to modify the url.
In my case it works perfect, I hope it helps you too.
Just check the directory in which you are trying to fetch the file. Your looking file may be not present in that directory. Otherwise, you are using the correct piece of code.
<a download href="~/home/Uploads/someDir/someFile.PNG" >View</a>

.htaccess allows images only

I know similar questions have been asked, but none of it guided me to the right solution.
What I want to do
Use .htaccess in a /uploads folder to ensure that only file with appropriate extension can be uploaded. (e.g. jpg, png)
What I have done
modify /etc/httpd/conf/httpd.conf
to allow overwrite of .htaccess file
create .htaccess file in /uploads folder
To test if .htaccess has been read, I have tried to put garbage in .htaccess file and access it from the browser. Corresponding error has been generated, therefore, .htaccess file is working properly.
Problem
The following script has been added to .htaccess
order deny,allow
deny from all
However, I am still able to upload files with any extensions to /uploads folder.
I have tried different suggestions from similar posts with no luck. Looking for new directions from you guys.
Thanks.
The name of the uploaded file is part of the body of the POST request the browser is making to the server, thus the .htaccess rules can't be enforced in your situation. Unless you are using some uploading schema, like creating a placeholder on the server and then submitting the file to that placeholder.
if you are using a GET method with base64 encoded string in your url, you can use .htaccess to redirect to an upload script base on the mime-type of that string. however I guess this is not what you trynna achieve. .htaccess is not appropriate in your case. if you need to control the extension of an uploaded file, you should make the process directly in your uploading script (php, python, whatever).

Is it possible for someone to get a list of all the files in Apache's www folder without FTP?

I have a 2.5GB file that I want to allow users to download after they buy it. I originally planned on hiding the file and then just using readfile to dump the file's contents with .zip headers but my GoDaddy server apparently won't allow me to use readfile on such a large file, so I'm stuck with changing the name of this important file every hour. But if someone can just list all the files on my www folder anyway then people can take it without paying for it.
Any suggestions?
As long as you don't allow indexing of the directory then they can't obtain a file listing. To do that create a .htaccess file in the directory and add:
Options -Indexes
Alternatively, if the folder has an index page this will also prevent the server disclosing a directory listing and instead serve the index page.
if you have more than 5 gig host so use the php exec command to copy your file with another name
let say you keep your file with a unguessable name in a unguessable folder
so whenever the buyer confirm the order then you copy the file to a known folder with user-generated name, then pass the link to user
if your host is linux then use cp command if it's windows use copy
use something like cp oldname.ext newname.ext or copy oldname.ext newname.ext
after a certain time you will delete the file in the known folder

How to not give direct acess to folder but to it's inside documents

environment
---------codeigniter framework
----------document sharing, links to download the files
mission
--------------files are allowed to download
--------------the folder which contains the files are
not allow to be seen by the user
Here I want to prohibit the user from seeing that folder, if I type the folder address I see all the files, I want to deny it. but the inside file not deny accessible
thanks in advance
Put a .htaccess file in that folder. .htaccess files are used by the server to follow some set rules. You should create this file with a basic text editor such as notepad, but not MSWord or a wysiwyg editor.
Search your FTP, there might already be one, it might also be hidden so make sure you open the FTP with the option to see all files option -a.
In the retrieved or newly created file, put the line
Options -Indexes
This will disable folder listing, giving a "Forbidden" error.
Another option, is to simply put an index.html or index.php file in the folder, that way when typing the folder name as URL will serve the index page instead of the folder root. And it also allows you to display a user friendly error.
Personnaly, I use both options.

Categories