Home > php教程 > PHP开发 > body text

How to convert php dynamic web page into html

高洛峰
Release: 2016-10-14 10:06:22
Original
1144 people have browsed it

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 follow the WeChat public account (Ruohong.com).

Generally speaking, search engines will regard the "?" character appearing in the dynamic web 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 current index How the server opens it when followed by 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 will specify the rewrite rule:

  rewriterule ^directory-([0-9]*.* index.php?category=$1 [l,nc]

  This instruction indicates: as long as the URL contains For page call requests for any static web page from "directory-0" to "directory-9", the server will return the "index.php? variable" address to the calling user

 Don't rush to edit the next rewrite rule, we have. It is necessary to test before changing the actual php page. We can test the above "rewrite rules". First, open a new browser window and enter "directory-1.htm" or "directory-" in the address bar. 1.html", if the page we see is displayed as "index.php?category=1", it means that the rewriting rules are working properly.

 3. Let search engines see our static page

Now, we need to allow search engines to see our “remodelled” new web page address. So, do we need to submit the website to the search engine again quickly? No need to work so hard, we just need to open the php file and edit it. But before doing so, remember to make a backup of every script you want to modify and store it on your hard drive. You then need to identify the different places where the program that changes the link address is created. It's better to make changes on the front end rather than in the background. The php file will get information in the form of "index.php?category=x" from the .htaccess file. We need to change these dynamically generated web page addresses and display them to users and search engines as static page addresses. That is, replace the part containing "index.php?category=" in all URLs with "directory-" and add the .html suffix.


source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template