.htaccess file

The Apache Web server provides a feature called .htaccess file, which provides commands to control a Web site. This file is simply a text file containing Apache directives.

The Apache Web server provides a feature called .htaccess file, which provides commands to control a Web site. This file is simply a text file containing Apache directives. Those directives apply to the documents in the directory where the file is located, and to all subdirectories under it as well. Other .htaccess files in subdirectories may change or nullify the effects of those in parent directories.

Here are some useful information:

Redirect non-www to www version of site

RewriteEngine On
RewriteCond %{HTTP_HOST} ^YourSite\.com [nc]
RewriteRule (.*) http://www.YourSite.com/$1 [R=301,L]

Or the code below that you don’t have to rewirte the domain:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Redirects

You can use .htaccess file to redirect any request for a specific page to a new page…

Redirect /OldDir/old.html http://site.com/NewDir/new.html

Redirect the missing file to index

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://%{HTTP_HOST}/ [R]

Popular .htaccess Hacks for WordPress

Protect the .htaccess file itself

# protect the htaccess file

order allow,deny
deny from all

Protect the wpconfig.php file

# protect wpconfig.php

order allow,deny
deny from all

Disable the Server Signature from showing

# disable the server signature
ServerSignature Off

Reference:

Apache Module mod_rewrite reference (http://httpd NULL.apache NULL.org/docs/2 NULL.1/mod/mod_rewrite NULL.html)

mod_rewrite-cheat-sheet-v2

Tagged with:
 

Comments are closed.



Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...