关于页面优化和伪静态_php技巧
关于页面优化和伪静态
1)版面优化
2)伪静态(重点涉及apache,smarty,正则)
详细内容:
一、版面优化:
版面优化其实主要涉及HTML,JS,CSS,XML之间的关系(XML相关在此不作描述).
1)一般来说,在资源共享的前提下,我们最基本的目的是让搜索引擎所收录(很多人被AJAX所迷惑,到处使用AJAX,但我的观点是,只有在后台或用户操作部分才使用).
因此,首先我们应该按搜索引擎的收录准则来设计(其实下面说的“伪静态”还不是为了搜索引擎,由于相关文档有好几个PAGE,请自行搜索),主要是html的使用问题,如
2)然后解决加载速度和内容纯度问题:
主要是以下几个原则:
1>不要为了版面美观,把无谓的HTML加上去,建议把版面美观的任务交给CSS,并认真考虑CSS的可重用性,HTML只作为对信息内容的描述(好像是XML的重点吧)。我在网上抽查了好一部分的站点,好的网站,html占总内容的50%以下,但有的站点,文字内容占总内容不到20%,
2>把JS,CSS写成文件.只要是利用了浏览器的CAHCHE,减少内容下载
3>HTML标签应该尽量减少嵌套,我见过夸张的一个站点,TABLE嵌套居然是11层..狂汗….
3)解决数据合理处理时间
这个涉及内容比较多,主要是
二、伪静态
这里主要描述apache,smarty的应用,当然,其实使用什么模板甚至不使用模板都没什么关系的,只是笔者长年使用smarty,深浓感受到它的强大
该部分主要针对的是对系统有控制权和对apache、正则较为熟悉的用户。
在这里,核心是强调正则的应用,如果你不会正则表达式,那么你就只能停留一成不变的抄袭阶段,甚至无法使用.而且正则在应用上普遍(基本上什么语言都有)、频繁和强大,笔者还是建议花点时间,学精一点,受用终生
对于搜索引擎,据我所知,关键是处理GET中的”?”、”&”.”php”,还有就是URL长度的问题就OK了,形式就看个人爱好了。
先说APACHE,关键是使用mod_rewrite,打开mod_rewrite模块(在httpd.conf中,把LoadModule rewrite_module modules/mod_rewrite.so前面的“#”去除)
如果使用了vhost(),可以在vhost里面加入类似下面的代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^xxx.com$
RewriteRule ^/([^\.\/]+)\.html$ /index.php?action=$1 [L]
解释:
以上配置不一定放在vhost里,按你个人要求放得合适就行。
第一行,表示该vhost将要使用rewrite(URL重写)
第二行,RewriteCond是用于如果后面条件符合(第一个参数满足第二个参数,其中第二个参数为正则表达式),则执行下面的RewriteRule指令,其中%{xxxx}表示是apache的变量,%{HTTP_HOST}表示URL的主机(域名),其它变量请查看apache2手册
第三行,实现url重写(重头戏),第一个参数为在浏览器中输入的url,满足该正则的uri才执行重写,第二个参数是重写规则,即把满足第一个参数的url 按照该规则转换成你须要的url在这里笔者必须指出,重写后的url如果包含”http://”,跳转后的地址会显示在浏览器的地址栏中。第三个参数是一些控制,如以上[L]表示该重写是最后一条,后面的重写规则不再被执行。
smarty部分:
主要是处理输出的页面内容,你使用apache的rewrite后,你页面中的链接当然使用了它的规则了,如:原来是 abc.php?action=doit就要改用类似abc/action-doit.html这样的方式表示,当然,你可以在做页面时自己手动去改,但我觉得这是比较笨的方法.为什么不去使用ob_xxxxx()去控制呢?(ob_xxxx()系的函数使用请参考php手册).在这里的介绍使用 smarty去代替,因为这样会更加灵活
在smarty中,使用register_outputfilter()注册一个处理方法即可,具体方法类似为:
//先定义好一个处理函数
function change_url($tpl_output, &$smarty)
{
$tpl_output=preg_replace(”/\/index.php?\?action=([^&]+)/i”,”/\\1.html”,$tpl_output);
return $tpl_output;
}
//该函数第一个参数是smarty的页面内容,第二个是smarty指针
//然后使用
$tpl->register_outputfilter(”change_url”);
register_outputfilter()方法是输出过滤函数,即交给 change_url($tpl_output, &$smarty)第一个参数是smarty处理后的页面内容
同类型的还有前过滤方法register_prefilter(),即把smarty模板交给第一个参数,详细使用方法请参考smarty手册

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Pseudo-static refers to the technology of accessing dynamic URL addresses by disguising them as static addresses, while hiding the PHP suffix is to modify the server configuration so that the PHP suffix is no longer displayed when accessing dynamic pages. The advantage of this is that it can enhance the security of the website and avoid being cracked, while also making it more beautiful and increasing the user experience. This article will introduce in detail how to use pseudo-static to hide the php suffix to improve the security and user experience of the website.

As we all know, optimizing the SEO of a website is a very important part of website operation. The default URLs of dynamic web systems (such as PHP) used by many websites have extensions (.php, .html, etc.), which will affect the SEO effect of the website. In order to improve the optimization effect of the website, a common practice is to change the dynamic URL to a pseudo-static URL to hide the extension name and improve the user experience and search engine ranking of the website. This article will take "pseudo-static hidden php suffix" as the theme, introduce how to achieve this optimization in PHP websites, and

Improve website security: Pseudo-static rules implement PHP suffix hiding. With the development of the Internet, website security issues have become increasingly prominent, including the prevention of malicious attacks and the protection of user data. An effective measure is to hide the PHP suffix through pseudo-static rules, which helps improve the security of the website and protect user privacy. In achieving this goal, we need to use some specific code examples to demonstrate how to achieve PHP suffix hiding. First, we need to understand what pseudo-static rules are. Pseudo-static is a method of converting dynamic web page links into

Vue is a modern JavaScript framework for building user interfaces. Its simplicity, efficiency and flexibility make it one of the preferred tools for front-end development. However, when developing Vue applications, how to optimize the loading speed and performance of the page becomes an important issue. This article will share some Vue development suggestions to help developers optimize page loading speed and performance. Loading Vue's asynchronous components using Vue allows us to define components to be loaded asynchronously. Dynamically import by using import()

Title: Page Cache Optimization Practice in Vue Development Introduction: In modern web development, optimizing page performance is an important and essential task. As a popular front-end framework, Vue provides some powerful mechanisms to help us optimize page caching. This article will introduce in detail how to use Vue for page cache optimization and provide specific code examples. 1. Understand the concept of page cache optimization. Page cache optimization refers to the use of caching mechanisms to cache loaded pages to avoid repeated network requests and thereby improve page processing.

With the rapid development of the Internet, website construction has attracted more and more attention. As we all know, optimizing the SEO of a website can improve the ranking and traffic of the website, and pseudo-static is an integral part of the SEO optimization of the website. In this article, we will use ThinkPHP6 to implement pseudo-static and further explore the optimization and implementation process of pseudo-static. What is Pseudo-Static state? Before explaining pseudo-static implementation, let’s first understand what pseudo-static is. Pseudo-static is a method of rewriting the URL address of a web page to make it appear

How to optimize page caching effect through PHP function? Overview: In website development, optimizing page caching is one of the important links in improving user experience and website performance. By properly setting the page cache, you can reduce the load on the server, speed up page loading, and improve user access experience. And PHP function is one of the tools we can use. This article will introduce some basic PHP functions and how to use them to optimize page caching. 1. Understand the PHP function: ob_start() function:

With the development of the Internet, web page optimization has become a very important topic. A smooth and fast web page is necessary for users because it is directly related to user experience. For website operation and maintenance, page optimization can reduce server load and improve website availability and stability. In response to these needs, PHP programmers can use some best practices for page optimization. Turning on cache caching can avoid repeated calculations. Without caching, each request requires a database query or other operation. and
