Articles for htaccess

Sometimes we face limitations of file size allowed to be uploaded using our PHP script. To overcome these problems we can simply add following lines to our .htaccess file and increase allowed size of files being uploaded using PHP (or some other scripts). 1 2 3 4 php_value upload_max_filesize 10M php_value post_max_size 10M php_value max_execution_time [...]

When moving your website from one domain to another, or just simply changing URLs and link, it is a good idea to use htaccess permanent redirect 301, as you users won’t be looking at 404 page. This is not the only benefit from htaccess permanent redirect 301, you get bonus from Google as well. If [...]

Sometimes you want to be sure to have ETags disabled. To disable ETags, make sure to include following snippet in your .htaccess file. 1 2 Header unset ETag FileETag None

ETags htaccess

In: .htaccess

21 Jul 2010

About Etags (text fom Wikipedia): An ETag, or entity tag, is part of HTTP, the protocol for the World Wide Web. It is one of several mechanisms that HTTP provides for cache validation, and which allows a client to make conditional requests. This allows caches to be more efficient, and potentially saves bandwidth, as a [...]

To have your website going through secure connection, you can use htaccess redirect. You can redirect all visits from that are not going through https, and force your website to use secure connection by using only htaccess. Us following htaccess snippet to force https. 1 2 3 RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

htaccess add www

In: .htaccess

20 Jul 2010

In order to force your domain using www, you can use following .htaccess snippet. This snippet makes htaccess add www to your domain name. 1 2 3 4 RewriteEngine on   rewritecond %{http_host} ^stuntsnippets.com [nc] rewriterule ^(.*)$ http://www.stuntsnippets.com/$1 [r=301,nc]

If you have problems with other websites stealing your bandwidth, and you want to prevent hotlinking, use following snippet and place code in your htaccess file: 1 2 3 4 RewriteEngine On RewriteCond %{HTTP_REFERER} !^http://(.+\.)?my-website-url\.com/ [NC] RewriteCond %{HTTP_REFERER} !^$ RewriteRule .*\.(jpg|gif|bmp|png)$ http://hotlink.my-website-url.com/hotlinking-is-not-allowed.jpg [L]

ErrorDocument 404

In: .htaccess

10 Jul 2010

In order to setup custom 404 page, and prevent user from viewing default error page, you can use ErrorDocument 404 in htaccess. Just copy/paste following snippet into your .htaccess file: ErrorDocument 404 /pages/errorDocument/error404.php More about ErrorDocument directive ErrorDocument directive doesn’t have to be used only for errors 404, and it can do couple of things [...]

Redirection htaccess

In: PHP

5 Jul 2010

Considering that you want to have nice URLs that are SEO optimized, you would have to pass parameters without using “?”. In this case we can use redirection htaccess. To make simple example, see snippet below: 1 2 3 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?page=$1 Use redirection htaccess: This redirection snippet will [...]

htaccess block IP

In: .htaccess

1 Jul 2010

If you have a need to block person or a bot on your website, there is an easy way to do this using htaccess. 1 2 3 4 order allow,deny deny from 4.4.4.4 deny from 22.22.22.22 allow from all After deny from, you will add IP address that you want to block. You can add [...]