Home >Backend Development >PHP Tutorial >About page optimization and pseudo-static_PHP tutorial
About page optimization and pseudo-static
1) Layout optimization
2) Pseudo-static (focusing on apache, smarty, regularity)
Details:
1. Layout Optimization:
Layout optimization actually mainly involves the relationship between HTML, JS, CSS, and XML (XML related will not be described here).
1) Generally speaking, under the premise of resource sharing, our most basic The purpose is to be included by search engines (many people are confused by AJAX and use AJAX everywhere, but my point of view is that it should only be used in the background or user operation part).
Therefore, first of all, we should follow the search engine inclusion guidelines to design (in fact, the "pseudo-static" mentioned below is not for search engines, since there are several pages of relevant documents, please search by yourself), mainly the use of html, such as
2) and then solve the loading speed and content purity issues:
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 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 the browser's CAHCHE is used 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... Crazy sweat...
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 even matter what template is used. It doesn't matter if you use templates, it's just that I have used smarty for many years and deeply feel its power
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 commonly used in applications (basically in any language (all have), frequent 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. , there is also the issue of URL length, which is OK, and 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 vhost() is used, You can add code similar to the following to vhost:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^xxx.com$
RewriteRule ^/([^./]+).html$ /index .php?action=$1 [L]
Explanation:
The above configuration does not necessarily need to be placed in the vhost, just put 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 Regular expression), 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 third line of the apache2 manual
to implement the url Rewriting (the highlight), the first parameter is the URL entered in the browser, and only the URI that satisfies the regular pattern will be rewritten. The second parameter is the rewriting rule, that is, the URL that satisfies the first parameter will be rewritten according to this rule. Convert it to the URL you need. The author must point out here that if the rewritten URL contains "http://", the redirected address will be displayed in the address bar of the browser. 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 processes the output page content. After you use apache's rewrite, of course the links in your page will use its rules, such as: it turns out to be abc.php?action= Doit should be expressed in a way similar to 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 What? (For the use of ob_xxxx() series functions, please refer to the PHP manual). The introduction here uses smarty instead, because it will be more flexible
In smarty, use register_outputfilter() to register a processing method, the specific method Similar to:
//First define 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 page content of smarty, The second one is the smart pointer
//Then use
$tpl->register_outputfilter("change_url");
register_outputfilter() method is the output filter function, which is handed over 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 means passing the smarty template to the first parameter. For detailed usage, please refer to the smarty manual.