When dynamic web pages meet search engines
Although dynamic web pages have many advantages over static pages, they hit a big snag in search engine retrieval. Regardless of any website, especially those corporate websites for marketing purposes, no one wants their web pages not to be indexed by search engines. But the fact is: many content pages of dynamic website design cannot be retrieved by search engines. For more PHP video tutorials, please pay attention to http://www.lampbrother.net Brothers Education.
Generally speaking, search engines will regard the "?" character appearing in the dynamic web page address as a "stop mark", and all parameters after it will be ignored. For example, for all subpages of "index.php?category=x", the search engine finally retrieves only one URL, which is the page index.php. As a result, dynamic web pages fall into the embarrassing situation of being unable to be discovered and retrieved by search engines, directly losing the opportunity to be discovered by users and the vast market space of search engines.
The reason why search engines do not support dynamic web pages
Dynamic web pages are driven by databases, which makes search engines face the danger of countless URLs and being trapped by the database and falling into an endless loop. This is what we call a spider trap. (spider traps). And once the spider is trapped by the website, its repeated access requests to the database will also cause the website server system to be completely paralyzed. In view of this, search engines will not read the characters after "?" in the URL of dynamic web pages.
Convert php to html static page
Although there is no guarantee that every dynamic page will be converted into a static html file, if the website is hosted on an apache server, only a simple small script can convert most of the dynamic pages into static html files. Dynamic pages are converted into html files.
1. Determine the PHP file that needs to be converted into a php file with the suffix html
Our target is those web pages that contain a lot of dynamic subpages. Taking "index.php?category=x" as an example, we need to convert the dynamic subpages after "index.php". For example, if there is a subdirectory named "arts and crafts" in the website, the url is "index.php?category=1", other subdirectories and this url are only different in the last variable, so we need to modify the index How the server opens it when following variables after .php.
2. Notify the server to open a php file after accepting a call request for an html page
We need to place an .htaccess text file in the directory where index.php is located on the server. The .htaccess file is a directory configuration settings file on the Apache server. It provides a method to change the configuration for the directory, that is, placing a file (.htaccess file) containing one or more instructions in a specific document directory to effect in this directory and all its subdirectories. The functions of .htaccess include setting web page passwords, setting files that appear when an error occurs, changing the home page file name, prohibiting reading of file names, redirecting files, adding mime categories, prohibiting the listing of files in directories, etc.
When you need to change the server configuration for a directory and do not have root permissions on the server system, you should use the .htaccess file. If the server administrator is unwilling to frequently modify the configuration, he or she can allow users to modify the configuration themselves through the .htaccess file, especially if the ISP provides multiple user sites on one machine and hopes that users can change the configuration themselves. Open some .htaccess functions for users to set by themselves. For vdeck users, you may need to create a text file first and then rename it to .htaccess in the admin panel. Now we need to specify some variables on the server side. For example, I need to change the variable "?category=x" to "directory-x.html", so as to eliminate the problem that dynamic pages cannot be retrieved by search engines.
Before we start creating server variables, we need to create a rewrite engine (url rewriting tool) in this new .htaccess file. Just write
rewriteengine on
on the first line of the file. This is equivalent to telling the server that we want to change the way some files are processed. The next line specifies the rewriting rules:
rewriterule^directory-([0-9]*.* index.php?category=$1 [l,nc]
这个指令表明:只要接到url中包含“directory-0”到“directory-9”的任意静态网页的页面调用请求,服务器将以“index.php?变量”地址返回给调用用户。
先别急着编辑下一条改写规则,我们有必要在更改实际的php页面之前先进行一下测试。我们可以对上面的"重写规则"进行测试。首先新开一个浏览器窗口,在地址栏中输入“directory-1.htm”或“directory-1.html”,如果我们看到的页面显示为“index.php?category=1”就表明改写规则工作正常。
3.让搜索引擎看到我们的静态化页面
现在,我们需要让搜索引擎能够看到我们经过“改头换面”的新的网页地址。那么,是不是需要赶紧把网站再向搜索引擎提交一遍呢? 不用这么费劲,我们只需打开php文件编辑一下就行了。不过在此之前,应记得将要修改的每个脚本都做个备份,将其存放在硬盘上。然后需要确定创建更改链接地址的程序的不同地方。最好在前端而不要在后台进行更改。php文件将会从.htaccess文件中得到形如“index.php?category=x”之类的信息。我们需要把这些动态生成的网页地址更改一下,并以静态化页面地址显示给用户和搜索引擎。即将所有url中包含“index.php?category=”的部分替换为“directory-”,并加上.html后缀。
一旦发现待修改的区域,在更改后要随时检查有无错误。如果在脚本中有错误而没有发现,纠正起来是相当棘手的,尤其在对php编码不熟悉的情况下。
以上就是PHP入门培训教程 php动态网页怎么转换成html的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!