关于页面优化和伪静态
关于页面优化和伪静态
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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











To set up a CGI directory in Apache, you need to perform the following steps: Create a CGI directory such as "cgi-bin", and grant Apache write permissions. Add the "ScriptAlias" directive block in the Apache configuration file to map the CGI directory to the "/cgi-bin" URL. Restart Apache.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

There are 3 ways to view the version on the Apache server: via the command line (apachectl -v or apache2ctl -v), check the server status page (http://<server IP or domain name>/server-status), or view the Apache configuration file (ServerVersion: Apache/<version number>).

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

How to view the Apache version? Start the Apache server: Use sudo service apache2 start to start the server. View version number: Use one of the following methods to view version: Command line: Run the apache2 -v command. Server Status Page: Access the default port of the Apache server (usually 80) in a web browser, and the version information is displayed at the bottom of the page.

How to configure Zend in Apache? The steps to configure Zend Framework in an Apache Web Server are as follows: Install Zend Framework and extract it into the Web Server directory. Create a .htaccess file. Create the Zend application directory and add the index.php file. Configure the Zend application (application.ini). Restart the Apache Web server.

Apache cannot start because the following reasons may be: Configuration file syntax error. Conflict with other application ports. Permissions issue. Out of memory. Process deadlock. Daemon failure. SELinux permissions issues. Firewall problem. Software conflict.

To delete an extra ServerName directive from Apache, you can take the following steps: Identify and delete the extra ServerName directive. Restart Apache to make the changes take effect. Check the configuration file to verify changes. Test the server to make sure the problem is resolved.
