Home  >  Article  >  Web Front-end  >  How to convert php dynamic web page to html?

How to convert php dynamic web page to html?

零下一度
零下一度Original
2017-04-25 13:42:214149browse

  When dynamic web pages meet search enginesAlthough dynamic web pages have many advantages over static pages,it has hit a big snag in search engine retrieval. Regardless of any website,especially those corporate websites,that are for marketing purposes, no one wants their web pages not to be indexed by search engines. But in fact, :many content pages of dynamic website design cannot be retrieved by search engines.

Generally speaking, search engines will regard the "?" characters appearing in the dynamic web address as "stop mark", in All parameters after it will be ignored. For example, for all subpages , of "index.php?category=x", the search engine finally retrieves only one , That 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 lose the opportunity to be discovered by users and search engines such a broad market space.

Reasons why search engines do not support dynamic web pages

Dynamic web pages are driven by databases,

This makes search engines face the danger of countless url and being trapped by the database and falling into an endless loop,This is What we call spider traps(spider traps). And once 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 url of dynamic web pages.  php

is converted into

htmlstatic page Although there is no guarantee that every dynamic page will be converted into a static html

file

,, but if the website resides on the apache server,You only need a simple small script to convert most dynamic pages into html files.  1.

Make sure you need to convert it into a

php file with the suffix html

Our target is those web pages that contain a lot of dynamic subpages. Take "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 are different from this url only in the last variable,So we need to modify the server’s response when index.php follows the variable. The way it opens.

 2.Notify the server to open a php file after accepting a call request for a html page

We need to place a .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, Place a file (.htaccessfile) containing one or more directives in a specific document directory, to act on this directory and all its subdirectories. The functions of .htaccess include setting web page passwords, setting files that appear when errors occur, changing home page file names, prohibiting reading of file names, redirecting files, adding mime categories, and prohibiting columns. Files in the directory, etc.

When you need to change the server configuration for a directory, but 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 can allow users to modify the configuration ,especially isp through the .htaccess file. When multiple user sites, are provided on one machine and users are expected to change the configuration themselves,, some .htaccess functions will generally be opened for use. The user can set it by himself. For vdeck users, may need to create a text file , and then rename it .htaccess in the management panel. Now we need to specify some variables on the server side. For example, ,I need to change the "?category=x" variable to "directory-x.html",This will eliminate the problem that dynamic pages cannot be Search engine retrieval issues.

  在开始创建服务器变量前,我们需要先在这个新建的.htaccess文件中创建一个rewrite engine (url重写工具)。只需要在文件第一行写上

 rewriteengine on

  这就等于告诉服务器我们要改变一些文件的处理方式。接下来的一行就要指定重写规则:

 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后缀。

Once you find an area to be modified, check for errors at any time after making changes. If there are errors in the script that are not found,it can be quite tricky to correct,especially if you are not familiar with phpcoding.

The above is the detailed content of How to convert php dynamic web page to html?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn