Posted on 15 February 2011.
One of the best things I love Apache web server is that it instantly enables you to share files and resources via plain web directory index listing without having to spend time making any fancy web pages to serve them.
However, there are times when you need to hide things out. To disable web directory listing, you need just a simple directive in .htaccess of that directory. Insert this line to disable apache files listing for this directory and all directories or folders underneath it: Continue Reading
Posted in .htaccess
Posted on 19 January 2011. Tags: .htaccess
Redirecting visitors to a maintenance page or other temporary page is an essential tool to have in your tool belt. Using HTAccess, redirecting visitors to a temporary maintenance page is simple and effective. All you need to redirect your visitors is the following code placed in your site’s root HTAccess: Continue Reading
Posted in .htaccess
Posted on 31 October 2010. Tags: .htaccess, cache, speed up
Increase your page load times and save bandwidth with easy and really effective methods using apache htaccess directives. This module controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server responses. The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access.
These HTTP headers are an instruction to the client about the document’s validity and persistence. If cached, the document may be fetched from the cache rather than from the source until this time has passed. After that, the cache copy is considered expired and invalid, and a new copy must be obtained from the source.
Continue Reading
Posted in .htaccess
Posted on 31 October 2010. Tags: .htaccess
Hotlink protection of images
Use this generator to create a .htaccess file for hotlink protection of your images and pictures. Hotlink protection can save you lots of bandwidth by preventing other sites from displaying your images. Continue Reading
Posted in .htaccess
Posted on 29 October 2010. Tags: .htaccess, development, PHP, scripting, subdomains
Dynamic subdomains using htaccess
This will render abcd.yourwebsite.com into yourwebsite.com/wor_out.php?url=abc Continue Reading
Posted in .htaccess, PHP
Posted on 14 October 2010. Tags: .htaccess
Redirect Request ending in .html/ to .html
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+)\.html/\ HTTP/
RewriteRule ^(.+)\.html/$ http://www.askapache.com/$1.html [R=301,L]
Posted in .htaccess, Programming
Posted on 03 September 2010. Tags: .htaccess, development, PHP, scripting
Setting up the server
The “good news” is that we can’t control the browser. It either sends the Accept-encoding: gzip, deflate header or it doesn’t.
Our job is to configure the server so it returns zipped content if the browser can handle it, saving bandwidth for everyone (and giving us a happy user). Continue Reading
Posted in .htaccess, PHP, Programming
Posted on 22 July 2010. Tags: .htaccess
SSI Variables
DATE_GMT=Sun Mar 8 22:58:56 2009
DATE_LOCAL=Sun Mar 8 15:58:56 2009
DOCUMENT_NAME=FOOTER.html
DOCUMENT_ROOT=/root-srv/protected/askapache.com/sec
DOCUMENT_URI=/includes/FOOTER.html
GATEWAY_INTERFACE=CGI/1.1
HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q=0.7,*;q=0.7
HTTP_ACCEPT_ENCODING=gzip,deflate
HTTP_ACCEPT_LANGUAGE=en-us,en;q=0.5
HTTP_CACHE_CONTROL=max-age=0
HTTP_CONNECTION=keep-alive
HTTP_COOKIE=__qca=12298910-686528-46510; __utmb=50625.1.0.11311
HTTP_HOST=www.askapache.com
HTTP_KEEP_ALIVE=300
HTTP_REFERER=http://www.askapache.com/htaccess/htaccess.html
HTTP_USER_AGENT=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6 (.NET CLR 3.5.30729)
LAST_MODIFIED=Sun Mar 8 14:53:50 2009
PATH=/bin:/usr/bin:/sbin:/usr/sbin
QUERY_STRING=
REMOTE_ADDR=24.123.215.60
REMOTE_PORT=4785
REQUEST_METHOD=GET
REQUEST_URI=/htaccess/
SCRIPT_FILENAME=/root-srv/protected/askapache.com/sec/includes/FOOTER.html
SCRIPT_NAME=/includes/FOOTER.html
SCRIPT_URI=http://www.askapache.com/htaccess/
SCRIPT_URL=/htaccess/
SERVER_ADDR=64.111.114.111
SERVER_ADMIN=webmaster@askapache.com
SERVER_NAME=www.askapache.com
SERVER_PORT=80
SERVER_PROTOCOL=INCLUDED
SERVER_SIGNATURE=
SERVER_SOFTWARE=Apache/2.0.61 (Unix) PHP/4.4.7 mod_ssl/2.0.63 OpenSSL/0.9.7e mod_fastcgi/2.4.2 DAV/2 SVN/1.4.2
UNIQUE_ID=dnbtH0Bvcm8A2ZHqcAAAAM
USER_NAME=
More SSI Information
- mod_include
- Apache Filters
- Introduction to Server Side Includes
- Apache Handlers
Posted in .htaccess
Posted on 28 June 2010. Tags: .htaccess
If you want to redirect all non-www requests to your site to the www version, all you need to do is add the following code to your .htaccess file:
in your .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This will redirect any requests to http://my-domain.com to http://www.my-domain.com. There are several benefits from doing that:
* It will avoid duplicate content in Google
* It will avoid the possibility of split page rank and/or split link popularity (inbound links).
* It’s nicer, and more consistent.
Note that if your site has already been indexed by Google without the www, this might cause unwanted side effects, like lost of PR. I don’t think this would happen, or in any case it would be a temporary issue (we are doing a permanent redirect, 301, so Google should transfer all rankings to the www version). But anyway, use at your own risk!
Something nice about the code above is that you can use it for any website, since it doesn’t include the actual domain name.
Redirecting www to non-www
If you want to do the opposite, the code is very similar:
in your .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]
In this case we are explicitly typing the domain name. I’m sure it’s possible to do it in a generic way, but I haven’t had the time to work one out and test it. So remember to change ‘my-domain’ with your domain name! Continue Reading
Posted in .htaccess
Posted on 04 March 2010. Tags: .htaccess
suppose you want /articles.php?cat=$1&art=$2 to become magazine/1/2
then you need these two rules:
#articles.php?cat=$1&art=$2
RewriteRule ^magazine/([^/]*)/([^/]*)$ /articles.php?cat=$1&art=$2&marker [L]
RewriteCond %{REQUEST_URI} /articles\.php [NC]
RewriteCond %{QUERY_STRING} ^cat=(.*)&art=(.*)
RewriteCond %{QUERY_STRING} !marker
RewriteRule (.*) http://mydomain/%1/%2? [R=301,L]
Posted in .htaccess