Showing posts with label htaccess. Show all posts
Showing posts with label htaccess. Show all posts

Saturday, May 17, 2014

Restrict image access from browser using HTACCESS



 When we want to restrict the image access from the browser other than the page, add the below code in htaccess file to apply.


RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC] 
RewriteRule \.(gif|jpg|png)$ - [F]

localhost need to be replaced by the domain name where the application is hosted. 

NOTE: Above code works in Apache (LINUX) not in windows

Monday, April 28, 2014

Redirect to maintenance page using HTACCESS



 Redirecting the whole site to maintenance page using HTACCESS

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^111\.11\.1\.11
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://www.domainname.com/maintenance.html [R=307,L]


Rewrite condition mentioned is to stop the redirection for that particular domain.

RewriteCond %{REMOTE_ADDR} !^111\.11\.1\.11

"maintenance.html" is the page where you want to redirect the website.

Wednesday, January 16, 2013

Upload huge files in PHP


When we try to upload huge files using PHP, we face many issues to upload. One of them might be the php_value upload_max_filesize which is by default 2M in php.ini

Still we may have other issues which we need to do fix them. Below are the steps we need to add in htaccess to fix the large file uploads.


php_value upload_max_filesize 10M
php_value post_max_size 64M
php_value max_execution_time 300


Friday, May 13, 2011

Force files to Download using HTACCESS

Add the below code in HTACCESS file to show download option whereas in PHP we can use header functions to give the download option for file.

AddType application/octet-stream .csv
AddType application/octet-stream .xls
AddType application/octet-stream .doc
AddType application/octet-stream .avi
AddType application/octet-stream .mpg
AddType application/octet-stream .mov
AddType application/octet-stream .pdf




Tuesday, December 7, 2010

Display Errors and Log errors in PHP

HTACCESS code to display errors(i.e Warnings & Fatal Errors) while running a PHP file in server is shown below.

php_flag display_errors off

HTACCESS code to log errors in Log file is php_flag log_errors. To off the Log files in the server we need to write the HTACCESS code as shown below.

php_flag log_errors off


To off the Errors displayed & also to OFF the log files the following HTACCESS code is used.


Options +FollowSymlinks
php_flag display_errors off
 
php_flag log_errors off


    

Friday, October 15, 2010

Upload Large Files with PHP

When we want to upload large files in PHP we would be changing the file max size limit in PHP ini file.

This can be done in our local system but when we need this is in Server where our Project is maintained it is not possible. So here is the Rewrite Rule in HTACCESS for PHP where we can change the maximum file size limit.

Rewrite Rule for Maximum File size is shown below.

php_value upload_max_filesize 20M

   

HTACCESS code to run PHP in HTML file

Using HTACCESS we can run the PHP code in an HTML file.

The REWRITE rule to write in HTACCESS file is shown below.

 AddType application/x-httpd-php .html .htm

Sunday, September 26, 2010

Rewrite condition for domain.com to www.domain.com using HTACCESS

Redirecting from domain.com to www.domain.com is mostly helpful as part of SEO. The rule for rewriting the site is shown below.

rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Just change the domain name to your site name to use the rewrite rule.

  

Sunday, August 22, 2010

HTACCESS code to redirect to 404 page

htaccess in Linux server is used for rewriting the URL & also used for redirecting to a Pre-defined error page(404 error page) when there is no file or page in the site.

Here is the rule for redirecting to Error page(404 page -- i.e. Page Not found)

Ex;- ErrorDocument 404 http://www.yoursitename.com/error404.php

Ex:- ErrorDocument 404 http://www.yoursitename.com/error404.html

we can define any filename for redirecting, in the above example, I've given an error404.php or error404.html as examples