.htaccess or search engine friendly URL

.htaccess or search engine friendly URL

.htaccess is the filename of a special configuration file that provides a number of directives (commands) for controlling and configuring the Apache Web Server, and also to control its many modules like mod_rewrite (for htaccess rewrite), mod_alias (for htaccess redirects), and mod_ssl.

Htaccess allows for decentralized management of configuration when placed inside the web tree. Htaccess is sometimes called: “HyperText Access”because one of the main functions of Htaccess files are to control access of HTTP (HyperText Transfer Protocol), which we know as the WWW. Htaccess is a very ancient configuration file, and is also one of the most powerful configuration files you will ever come across.

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.

You have to be careful when editing .htaccess files, as a small mistake can make your Web site stop working. You should immediately test the site to be sure it works.

 

.htacce mostly uses for the extension hidding for example if websites are running on php and developer are not want to display .php extension then it is useful to use .htaccess file and make it as directory structure or you can also display as .html or .hml

.htm or .html file are search engine friendly so it is useful for SEO working

 

Sometimes you may need to make sure that the user is browsing your site over securte connection. An easy to way to always redirect the user to secure connection (https://) can be accomplished with a .htaccess file containing the following lines:

RewriteEngine On 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Please, note that the .htaccess should be located in the web site main folder.

In case you wish to force HTTPS for a particular folder you can use:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]

The .htaccess file should be placed in the folder where you need to force HTTPS.

Here are the most notable and useful .htaccess examples…

Custom error pages

The most common errors are 404 (Not Found) and 500 (Internal Server Error). Design your custom Web pages for these errors (you aren’t limited to these errors, you can create an error page for each and every error). Add the following commands to your .htaccess file…

RewriteEngine On

ErrorDocument 404 /404.html
ErrorDocument 500 /500.html

Redirects

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

Redirect /domain/old.html http://site.com/new.html

Server-side redirects are very useful for shortening affiliate links. Your visitors won’t be turned off by long links that are obviously affiliate links. For example, to create a redirect at the URL:

 

Redirecting domain.com to www.domain.com

If search engines find both www and non-www links from other sites to your site, they may treat http://domain.com and http://www.domain.com as two different websites with the same content. This means that your site can be penalized for duplicate content.

Many experts recommend to set up a 301 redirect (permanent redirect) from YourSite.com to www.domain.com…

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

Replace “domain.com” with your real domain name.

The .htaccess file is very obscure and extremely useful when used properly. The above htaccess examples cover only a few possible uses of this powerful tool. For more information, see…

http://httpd.apache.org/docs/1.3/howto/htaccess.html

 
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.