Today we're going to cover a few simple tricks you can perform with your .htaccess file which will make your visitors that bit happier.
View Screencast
Alternatively, Download the video, or subscribe to Webdesigntuts+ screencasts via iTunes or YouTube!
Snippets
Firstly, it's likely you'll want to direct your visitors to a definite location, irrespective of the exact url they enter. This can be taken a step further by specifying friendly urls. Lastly, we make sure that directory listing is disabled, preventing users from browsing the contents of our directories.
<IfModule mod_rewrite.c> # For security reasons, Option followsymlinks cannot be overridden. Options +FollowSymLinks RewriteEngine on # Restrict your site to only one domain RewriteCond %{HTTP_HOST} !^justinhubbard\.me$ RewriteRule ^(.*)$ http://justinhubbard.me/$1 [L] # Friendly URL RedirectMatch 301 http://justinhubbard.me/blog/index.php?work=websites(.*) http://justinhubbard.me/blog/websites/$1 # Make sure directory listing is disabled Options All -indexes </IfModule>
This final snippet enables the Gzip module. Gzip compresses your files server-side, before sending them to the browser for extraction. As you can imagine, this speeds up download times quite significantly..
<ifModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </ifModule>
Additional Resources
- 5 Fun and Practical Htaccess Solutions on Nettuts+
- .htaccess Files for the Rest of Us on Nettuts+
- The Ultimate Guide to .htaccess Files on Nettuts+
- Using htaccess Files for Pretty URLS on (wait for it) Nettuts+
Subscribe below and we’ll send you a weekly email summary of all new Web Design tutorials. Never miss out on learning about the next big thing.
Update me weeklyEnvato Tuts+ tutorials are translated into other languages by our community members—you can be involved too!
Translate this post