Skip to main content

Htaccess

The htaccess files they are directory-specific configuration files for NCSA-compliant web servers, such as the Apache web server. All settings in the .htaccess file apply to the directory where the file was stored, as well as all subdirectories, and take effect immediately. You do not need to restart the server.

Different uses of the .htaccess file

Typical uses of the .htaccess file are the rewrite and redirect URLs, error document management and access protection for individual files or entire directories.

Rewriting from a dynamic URL to a static URL

Using Apache's moderation-rewrite module that is installed and enabled on most servers, a dynamic URL can be rewritten in such a way that it looks like a static URL to humans and search engines.

Example: input.htaccess to enforce the appropriate host:

RewriteCond % {HTTP_HOST}! ^ Www.domain.de$ RewriteRule ^ (. *) $ http: // www.domain.de/ $1 [QSA, L, R = 301]

Redirect from an old URL to a new one

Redirecting an old URL to a new one is an alternative when there is one domain transfer or they exist to redirect for other reasons (such as relaunch, restructuring). Again, a permanent redirect must be selected. In the above code, instead of the last line, the following is inserted:

RewriteRule ^ alteseite.html$ /neueseite.html [R = 301, L]

Redirect by «www»

Many domains can be retrieved with www. or without www. The redirect "without www." to "with www." it is essential because this can avoid duplication of content. Search engines recognize domain names with www. as the default address if the redirect points to this URL. The [NC] in the code below means "case sensitive", in other words, the 'domain names that are in uppercase are redirected.

RewriteEngine On RewriteCond % {HTTP_HOST} ^ domain.de$ [NC] RewriteRule ^ (. *) Http: // www.domain.de / $1 [L, R = 301] 

Image theft protection

The .htaccess file is a way to prevent a user from downloading an image from a web portal or inserting it into their own web portal. This not only protects your images from being subject to content theft, but also prevents traffic from being stolen from the web portal that provided the image as a resource by the user who has integrated the image into their own web portal.

The first line of code exclude this rule for your own website, so calling an image does not result in an error message, because all images must display correctly on your website. The second line specifies that all external requests for graphic files should cause an error message to be displayed.

RewriteCond % {HTTP_REFERER}! ^ Http: // www.domain.de/ [NC] RewriteCond % {HTTP_REFERER}! ^ $ RewriteRule. (Jpe? G | gif | png) $ - [F]

Importance for SEO

URL rewriting and redirection in particular are of importance for search engine optimization. The redirect status is fundamentally significant from an SEO perspective. If nothing is specified here, most servers interpret this as a temporary redirect and they regard it as a 302. However, if the redirect is to be interpreted as a permanent redirect (301), it must be explicitly specified because a 301 redirect transfers the ranking of the linked source to the destination resource.

A 302 redirect is interpreted by Google differently. The forwarding is considered only temporary and the fame of the source linked not transferred to the destination resource. When redirecting or rewriting URLs, as well as when directing to a "www." Resource, a 301 redirect must be selected.

The decision to redirect to the "www." if you call a URL without the abbreviation www. It is also essential because a preferred canonical URL makes it easy for Google to identify the default address. The same duplicate content is avoided. In all redirects it is essential to ensure that no 404 error codes are issued. Google does not usually index the sites that show a 404 error code in the server solution. In this way, a technically incorrect handling of redirects through .htaccess can have a great impact on the reputation of a web portal and sometimes , result in the website not being indexed or degraded in the rankings.

Web Links