I created a php script that allows you to download and upload files. Files are saved to a directory XXX. Can I add an htaccess file to protect files in this folder? I would want that people must login to my web site to download files. I would want that people who know the position of XXX can not download file without to login to control panel of my web site. What should I write in this htaccess file? The site is hosted. Files can have any extension.
You can do something like this in your htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^files/([^/]+)/([^/]+).zip /download.php?folder=$1&file=$2 [NC]
All requests to files/XXX/YYY.zip will be rewritten to files/download.php?folder=XXX&file=YYY and your php can handle the authentication.
Related
I have a site https://sitename.com/web (example). So, full path to page is sitename.com/web/index.php. On ftp server there is folder /web which also contain second page file - index-2.php. How to avoid creating /web-2/ folder and redirect index-2.php to sitename.com/web-2 ?
Easy, create an .htaccess file inside the root folder of your site, then add the following lines to it:
RewriteEngine On
RewriteRule ^web-2$ index-2.php [QSA,L,NC]
This site might help you with htaccess:
https://www.htaccessredirect.net/
A nice tutorial on .htaccess files also below:
https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file
I don't have my .htaccess file for my magento installation which is by default present for all the fresh magento installation.
Now I have to remove "index.php" from my wesite url and found out htaccess file needs to be edited. But, there is no .htaccess file in my magento root folder.
Also, I have made a lot of changes to the website and don't want to do a fresh installation to get the .htaccess file.
Also, when I access my admin panel it also needs "index.php" in the URL.
Please, can someone help me with this.
To Remove the inde.php from the URL you need to enable Web Server Rewrites.
You can enable Web Server Rewrites suing below steps:
Login in Backend, from Top Navigation click on System >> Configuration >> Web
Select Use Web Server Rewrites to YES in Search Engines Optimization group.
If you need .htaccess file, you can donwload the compatible magento zip file and can use its .htaccess. There is no need to install magento for this.
each month many gigabytes of traffic on my site is being consumed by various sites, mostly in italy according to my stats. On further review of my raw access logs, they have built in direct reference links to css and png files in my site. I can just rename them but that wont stop them accessing a page in my site to get their full urls and keep accessing them.
Is there a way to block access to css and image files in my site unless they come from the same domain, somehow?
Regards
Greg J
Try adding this to the .htaccess file in your web document root folder (often public_html or htdocs) (edit the name of the domain):
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^yourdomain\.com
RewriteRule (?:jpg|png|gof|css) - [F]
This assumes that mod_rewrite is both installed and activated for htaccess files.
If you are not sure, to check if mod_rewrite is installed, look at the list of installed modules in the output of phpinfo();
By default, mod_rewrite is not enabled for htaccess files. If you are managing your own server, open httpd.conf
and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All
Ok, I'm clueless here...
I need to rewrite a directory structure and all sub-directories within it to a directory within the same server, but a root that is before the directory.
For example:
http://www.mydomain.com/Themes/default/css/folder
and all directories called upon after folder. Such as folder/sub_folder or folder/afolder/anotherfolder, it needs to include ALL sub-directories within the folder directory.
should be redirected to this:
http://www.mydomain.com
How do I do this via a .htaccess file within the folder path http://www.mydomain.com/Themes/default/css/folder?
Please someone help.
Thanks guys :)
The files within the directory structure still need to be accessible for that structure when called via PHP, but I don't want people being able to browse to http://www.mydomain.com/Themes/default/css/folder and be shown all subdirectories within that folderpath and/or all files. Same thing for all sub-directories that follow that folder path.
I'd like to be able to place the .htaccess file within the http://www.mydomain.com/Themes/default/css/folder directory on the server, but don't know exactly what code to use for this.
ALSO, even more challenging... The domain name can change, so I'd rather not use the domain name within the .htaccess file, instead perhaps use .. or . to go up a directory or a different method of grabbing the domain name within the .htaccess file.
Create a .htaccess file in /Themes/default/css/folder and place these lines there (it requires mod_rewrite):
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ http://%{HTTP_HOST}/ [R=301,L]
It will redirect (301 Permanent Redirect) all requests to a folder to a homepage. If file is requested, it will allow it.
If you want to have it working for folders as well as files then remove the RewriteCond line -- it will redirect ALL requests (even for non-existing URLs) to a homepage.
If you will see "500 Internal Server Error" after creating such file, then it is your server configuration: mod_rewrite may not be enabled or it's directives (RewriteRule, RewriteCond, RewriteEngine) are not allowed to be placed in .htaccess. In any case -- check Apache's error log for exact error message (it will give you the exact reason).
http://www.besthostratings.com/articles/prevent-directory-listing.html
IndexIgnore *
I am looking for a away to redirect a visitor trying to access my download folder
http://domain.com/downloads/
- this is the download folder where my files are located.
I want to redirect the visitor to a registration page.
and also if they try to direct download the file
http://domain.com/downloads/installer.exe
I would like to get redirected to my registration page
http://domain.com/registration/register.html
I think this will do it.
RewriteRule ^downloads(.*)$ http://domain.com/registration/register.html [R=301,L]