What is a .htaccess file?

What is an .htaccess file?

Htaccess (HyperText Access) is a simple configuration file that permits programmers, designers and developers to change the configuration of the Apache web Server so as to supply further functionalities.

Using .htaccess files permits you to manage the behavior of your website or a particular directory on your site. So, if you place  .htaccess in the root directory, it’ll have an effect on your entire site (www.topexamplesite.com). When you place it in a specific directory, it’ll solely have effect on that directory (www.topexamplesite/content).

How to create and upload an .htaccess File

Creating an .htaccess file is very simply.

You should open Notepad, switch off word-wrap, add the code and save the file for example as:  htaccess.txt

Upload the file to the needed directory on your web hosting server and then you should rename it:  “.htaccess”

IMPORTANT , a .htaccess file should be using 644 permissions and uploaded in ASCII mode.

.htaccess will not work on Windows-based servers.

Example of .htaccess File for:

Basic WordPress :

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Multisite WordPress (3.5 and up):

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]





No Comments

    Leave a reply