The htaccess file has always been a file that is carefully studied by SEO experts at home and abroad, because in many cases this file takes over the highest configuration of the website (such as a virtual host). If the .htaccess file can be used properly, it can not only achieve unexpected results The SEO effect can solve many difficult problems related to the website.
To be precise, the .htaccess file is a file under the Linux system, which can be seen from its file name. Moreover, this file has strict encoding and format. One more space or one less space may cause a 500Error on the server. Therefore, we do not recommend using the Notepad that comes with the Windows system to edit this file. The best way to edit manually is to use an advanced text editor like UE or notepad2. If it is inconvenient to download or there are errors in manually written files, the online htaccess text editor is also highly recommended. This editor is currently very complete and has added many new features under secondary development. It is easy to use and perfectly supports multiple conditions. Intelligent generation of htaccess files for complex tasks.
In the following, we will also introduce the usage and precautions of this htaccess online generator.
1. Turn on the image hotlinking prevention function of the website
If the traffic of the website is limited, it is very necessary to prevent image hotlinking. Not only can it reduce traffic waste, but it can also reduce server load. To enable the image hotlink protection function, you need to add the following code to the htaccess file:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://( www.)?allow1.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://( www.)?allow2.com(/)?.*$ [NC]
RewriteRule .*.(gif|jpg|jpeg|bmp|png)$ www.***.com can be accessed. This is a very bad experience for search engines and can easily cause weight dispersion. What we have to do is to unify the URLs with www and the URLs without www.
We do not recommend manually writing this code. The automatic generation program has made perfect judgments. You only need to switch to the "WWW domain name redirection" tab and fill in the address bar behind the WWW domain name redirection that you want to eventually use. Just a domain name! Note that the domain name filled in here must be a complete URL, such as http://www.***.org or http://***.org . The program will automatically determine whether to use forward or reverse redirection based on your input.
5. It’s very annoying that the default document doesn’t fit the description, and I have to make a jump page.
Some virtual hosts are different and do not use the default file names, or the order is not mainstream. Then you can define the file name of this page by yourself through the following code. For example, index.htm, default.php, etc.:
DirectoryIndex index.php
This line of code sets index.php as the default home page. For other pages, please directly replace index.php in the example. If the website has multiple pages that need to be used as the homepage, please write the file in the format of DirectoryIndex index.php index2.php. This setting is in the htaccess generator. You only need to fill in the file name of the homepage in sequence, which is very convenient.
6. Enable website image caching through htaccess
Some web hosts limit website traffic. If the browser downloads the most commonly used image files from the server every time, a lot of bandwidth will be wasted. Therefore, you can enable image caching, and the browser will automatically load image files from the cache before the cache expires. This function adds the following code to the file:
<FilesMatch “.(gif|jpg|jpeg|png|ico)$”>
Header set Cache-Control “max-age=3600″
</FilesMatch>
It should be noted that the unit of 3600 above is seconds, which is the timeout time. The gif and so on in the above picture are image file suffixes, which means they are effective for these files. If using the auto-generate tool, select a timeout for the "Turn on image caching for site" tab in order to turn this option on. Currently there are ten minutes, one hour, one day and other options to set.
7. Fixed 301 and 302 web page redirection
404 errors caused by page transfers are a headache for all of us, but we only need to make a 301 redirect to completely solve this problem. Add the following code to the htaccess file:
Redirect permanent /old.htm http://www.***.com/new.htm
The former parameter uses a relative path or a directory name, and the latter parameter must fill in the complete URL. Only in this way can it be effective and error-free. In SEO, search engines will soon update the included web pages according to your settings.
In addition, htaccess can also implement functions such as MIME file type modification, domain name redirection, etc. Therefore, making full use of this file will make your website construction more convenient.
Finally, I would like to recommend an htaccess online generation editor to everyone: http://www.wangqu.org/htaccess/ , which is worth saving on your computer for emergencies.
htaccess