1. Web Design
  2. UX/UI
  3. UX Design

Quick Tip: Point Visitors in the Right Direction With .htaccess

Scroll to top
1 min read

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.

1
2
<IfModule mod_rewrite.c>
3
4
        # For security reasons, Option followsymlinks cannot be overridden.
5
        Options +FollowSymLinks
6
	RewriteEngine on
7
8
	# Restrict your site to only one domain
9
	RewriteCond %{HTTP_HOST} !^justinhubbard\.me$
10
	RewriteRule ^(.*)$ http://justinhubbard.me/$1 [L]
11
	
12
	# Friendly URL
13
	RedirectMatch 301 http://justinhubbard.me/blog/index.php?work=websites(.*) 
14
        http://justinhubbard.me/blog/websites/$1
15
	
16
	# Make sure directory listing is disabled
17
	Options All -indexes
18
19
</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..

1
2
<ifModule mod_gzip.c>
3
  mod_gzip_on Yes
4
  mod_gzip_dechunk Yes
5
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
6
  mod_gzip_item_include handler ^cgi-script$
7
  mod_gzip_item_include mime ^text/.*
8
  mod_gzip_item_include mime ^application/x-javascript.*
9
  mod_gzip_item_exclude mime ^image/.*
10
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
11
</ifModule>

Additional Resources