About page optimization and pseudo-static
1) Layout optimization
2) Pseudo-static (focusing on apache, smarty, and regularity)
Details:
1. Layout optimization:
Layout optimization actually mainly involves HTML, JS, CSS, and XML relationship (XML related will not be described here).
1) Generally speaking, under the premise of resource sharing, our most basic purpose is to be included by search engines (many people are confused by AJAX and use AJAX everywhere, but I The point of view is that it is only used in the background or user operation part).
Therefore, first of all, we should design according to the search engine inclusion guidelines (in fact, the "pseudo-static" mentioned below is not for search engines, because there are several related documents PAGE, please search by yourself), mainly the use of html, such as
2) Then solve the problem of loading speed and content purity:
Mainly the following principles:
1>Don’t add unnecessary HTML for the sake of beautiful layout. It is recommended to leave the task of beautiful layout to CSS and seriously consider the reusability of CSS. HTML is only used as a description of the information content (it seems to be the focus of XML). I randomly checked a lot of sites on the Internet. For good websites, html accounts for less than 50% of the total content, but for some sites, text content accounts for less than 20% of the total content.
2>Write JS and CSS into files. As long as it is Use the browser's CAHCHE to reduce content downloads
3> HTML tags should be nested as little as possible. I have seen an exaggerated site where TABLE nesting is actually 11 levels...
3) Solve the problem of reasonable data processing time
This involves a lot of content, mainly
2. Pseudo-static
This mainly describes the application of apache and smarty. Of course, it doesn’t actually matter what template is used or even whether it is used at all. It’s just that the author has used smarty for many years and has a deep feeling of it. It's powerful
This part is mainly aimed at users who have control over the system and are familiar with apache and regular expressions.
Here, the core is to emphasize the application of regular expressions. If you don’t know regular expressions, then you can only stay in the immutable plagiarism stage, or even be unable to use it. Moreover, regular expressions are common in application (basically in all languages) and frequently and powerful, the author still recommends spending some time, learning more, and using it for life
For search engines, as far as I know, the key is to deal with "?", "&"."php" in GET, and the URL length. The question is OK, the format depends on personal preference.
Let’s talk about APACHE first. The key is to use mod_rewrite and open the mod_rewrite module (in httpd.conf, remove the "#" in front of LoadModule rewrite_module modules/mod_rewrite.so)
If you use vhost(), you can add something like the following to vhost Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^xxx.com$
RewriteRule ^/([^./]+).html$ /index.php?action=$1 [L]
Explanation:
The above configuration does not work It must be placed in the vhost. Just place it appropriately according to your personal requirements.
The first line indicates that the vhost will use rewrite (URL rewriting)
The second line, RewriteCond is used if the following conditions are met (the first parameter satisfies the second parameter, where the second parameter is a regular expression) , then execute the following RewriteRule instruction, where %{xxxx} represents an apache variable, %{HTTP_HOST} represents the host (domain name) of the URL. For other variables, please refer to the apache2 manual
The third line implements url rewriting (the highlight), The first parameter is the URL entered in the browser. Rewriting will only be performed if the URI meets the regularity. The second parameter is the rewriting rule, that is, the URL that meets the first parameter is converted into the URL you need according to the rule. The author must point out here that if the rewritten URL contains "http://", the redirected address will be displayed in the browser's address bar. The third parameter is some control. For example, [L] above indicates that the rewrite is the last one, and subsequent rewrite rules will no longer be executed.
smarty part:
Mainly processing the output page content. After you use apache's rewrite, the links in your page will of course use its rules. For example: if it is abc.php?action=doit, it should be changed to something like abc. /action-doit.html. Of course, you can change it manually when making the page, but I think this is a stupid method. Why not use ob_xxxxx() to control it? (ob_xxxx() system Please refer to the PHP manual for the function usage). Use smarty instead for the introduction here, because it will be more flexible. In smarty, just use register_outputfilter() to register a processing method. The specific method is similar to:
// Define it first A processing function
function change_url($tpl_output, &$smarty)
{
$tpl_output=preg_replace(”//index.php??action=([^&]+)/i”,”/\1.html” ,$tpl_output);
return $tpl_output;
}
//The first parameter of this function is the smarty page content, and the second is the smarty pointer
//Then use
$tpl->register_outputfilter("change_url") ;
register_outputfilter() method is the output filter function, which is passed to change_url($tpl_output, &$smarty). The first parameter is the page content processed by smarty.
The same type also has the pre-filtering method register_prefilter(), which is to pass smarty The template is passed to the first parameter. For detailed usage, please refer to the smarty manual.
The above introduces the asp.net pseudo-static regarding page optimization and pseudo-static, including the content of asp.net pseudo-static. I hope it will be helpful to friends who are interested in PHP tutorials.