My .htaccess tricks

To show a directory listing specifically in that directory only place this in the .htaccess file that resides in that folder:

IndexOptions -FancyIndexing
 Options +Indexes




To deny a directory listing, place this the the .htaccess in that directory or in a higher directory:

 Options -Indexes
 

Now a 403 error will be returned instead.



To redirect to a subdirectory or a folder:


RewriteEngine On
RewriteBase /
RewriteRule ^index.(.*)?$ http://domain.com/subfolder/ [r=301]

This will redirect any attempt to access a file named index.something to your subfolder, whether the file exists or not.

A simple HTML redirect is an alternative:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com"></HEAD>
<BODY>
Optional page text here.
</BODY>
</HTML>

Leave a comment