As a mainstream blogging system, WordPRess is favored by many webmasters. In fact, wordpress is also very conducive to SEO. Today, let’s talk about the fixed link settings and optimization in wordpress.
There are generally 5 forms of fixed links: the default ?p=id form, date + name form, number form, and custom structure. You can find that most WordPress websites use the last custom structure form, because this form is conducive to search engine optimization. So, how should the custom structure be set up?
There are two general custom structures: directly set to /%postname%/ or set to /%postname%.html. Among them, %postname% is the custom URL of the article. This will automatically generate a link with the article title as the URL when writing the article. Of course, Chinese websites generally use plug-ins to translate, or edit them into Pinyin form yourself. I personally recommend the pinyin format. You can write the main keywords of the article content in pinyin, which is more conducive to ranking.
The two custom structures mentioned above are both very good, so which one should I choose? According to the author's humble opinion, it is better to choose the /%postname%/ structure. Why do you say that? If you choose the former, in fact the search engine will treat your article as the homepage of the website subdirectory, and if you choose the latter, it will be treated as an html document in the root directory. So, which one has higher weight, the homepage of the subdirectory or the ordinary page of the root directory? It should be the homepage of the secondary directory, so the author recommends using the former, that is, a structure like /%postname%/.
After setting up the permalink, just click "Update". If it is a Linux host, WordPress will automatically generate .htaccess, which is equivalent to setting up the fixed link; however, a Windows host will be a lot more troublesome, and the webmaster needs to write httod.ini himself and upload it to the root directory. A sample is provided here.
[ISAPI_Rewrite]
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /sitemap.html /sitemap.html [L]
RewriteRule /favicon.ico /favicon.ico [L]
RewriteRule /wap(.*) /wap$1 [L]
RewriteRule /content/uploads/(.*) /content/uploads/$1 [L]
RewriteRule /wp-(.*) /wp-$1 [L]
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]
Just paste the above code into a text document, save it as httpd.ini and upload it to the root directory. It should be noted that due to the serious flaws of the win host in this regard, the above code also has a small loophole, that is, all files on the website are inaccessible. The solution is also very simple. If it is a file in the root directory, just add RewriteRule /File name/File name [L]. For directories other than those that already appear in the template, just add RewriteRule /Folder directory/(.*) /folder directory/$1 [L] will do. At this point, the WordPress fixed link settings are finally completed.
So, after setting up your own fixed link, can the default link in the form of ?p=id still be accessible? The answer is yes. Let’s talk about the advantages and disadvantages of linux hosts and win hosts again. If it is a Linux host, accessing a webpage in the form of ?p= will automatically jump to the article page of the alias (i.e. the link you set yourself) with a 301 jump. However, this will not happen with the Win host, which means that every article page can be used. Two different link accesses. This is very unfriendly to search engines, so it is necessary to make the short link 301 jump to the alias link. So how to set it up? Just find header.php in the template and add the following code to the header.
if($_GET['p']||$_GET['page_id']){
if($_GET['p'])$id=$_GET['p'];
if($_GET['page_id'])$id=$_GET['page_id'];
$post= get_post($id);
$name=$post->post_name;
header('HTTP/1.1 301 Moved Permanently');//Send 301 header
header('Location: '.bloginfo('url').'/'.$name.'/');
exit();
}else if($_GET['cat']){
$id=$_GET['cat'];
$cat=get_category($id);
$name=$cat->slug;
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.bloginfo('url').'/cat/'.$name.'/');
exit();
}else if($_GET['tag']){
$name=$_GET['tag'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.bloginfo('url').'/tag/'.$name.'/');
exit();
}?>
Haha, now it’s finally done. Whether it’s a Linux host or a Win host, the fixed link is really ready. It can also be seen from this that if you use the WordPress system, try to use a Linux host. The above is the experience of the webmaster of Sleep Pillow Network ( www.89948.net ). Comments and reprints are welcome. Please indicate the link when reprinting, thank you!
Editor in charge: Personal space of hadron author qzonelove