PHP pseudo-static

Source: Internet
Author: User
Tags php get url

Title: PHP pseudo-static
Author: insun
Php url pseudo-static SQL _asp/php-rewrite.html

Php pseudo static (url rewrite) apache configuration

Three methods to implement PHP pseudo static page:

Implementation of friendly URL (vomit blood recommended)

PHP implementation of pseudo Static Page specific implementation of

PHP pseudo static and anti-injection

Php parameter transfer and php get url parameters after reasonable arrangement of

Php to achieve pseudo static page of the two methods (including two methods of url rewriting PHP page to achieve static explanation and detailed code

Recently, I have worked as an intern in a company. I used php crawlers to crawl website pages, store them in a database, write a website to call the database, and then perform SEO, requiring collection and remote data localization and pseudo-static data, keyword optimization, no dead chain, no islands; after completion, you can enter the project team.
PHP implements pseudo-static files for SEO (Search Engine engines or directories). In fact, PHP files are used on the server. That is to say, the search engine does not like/page. php? Id = 4 is a page like/4.html, which is very friendly (helpful for indexing). Of course, you won't create N html pages directly.
I. The simplest method
URL rewriting in Apache + PHP (pseudo-static)
1. Check whether apache supports mod_rewrite.

In the httpd. find LoadModule rewrite_module modules/ In the conf file, and remove the # (if any, uncomment it). in Linux, we recommend that you use the Xampp installation package, the LoadModule has basically been de-Annotated, so it generally does not need to be modified.
Then, use phpinfo () to check whether the environment configuration supports mod_rewrite.

2. Search for Options FollowSymLinks in http. conf and change AllowOverride None to AllowOverride All.
In this case, you can add url rewrite rules after http. conf if you have the http. conf permission.
For example
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^ (. *)/(%0-9%}1,%}.html $1/page. php? Id = $2
Second, we had to create a directory in the Code root directory. htaccess file, which is relatively simple to create. There are three methods, the simplest of which is to create 1. htaccess and save it. htaccess, rename and ftp software modification under cmd.
3. rewrite Rules
Let's look at the example.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^ (. *)/(%0-9%}1,%}.html $1/page. php? Id = $2
$ Is the Terminator. A regular expression is written before. $1 gets the first sub-mode (Dongdong in parentheses) and $2 gets the second sub-mode.
Friendly reminder ^ is the beginning. Do not forget to add it
If there are two parameters, it is also very easy to handle.
Also, if the browser displays 4.html (the link in your file is written as .html), is page. php actually called? Id = 4. In this way, all input columns of the browser are html, Which is pseudo-static.
Of course, if you rewrite different regular expressions, the displayed url is certainly different, as you like.
If you encounter multiple rows, do not use the extra points. The following is true:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^ (. *)/(%0-9%}1,%}.html $1/page. php? Id = $2
RewriteRule ^ (. *)/index.html $1/index. php
RewriteRule ^ (. *)/wenzhang.html $1/wenzhang. php
RewriteRule ^ (. *)/gushi.html $1/gushi. php
RewriteRule ^ (. *)/sanwen.html $1/sanwen. php
RewriteRule ^ (. *)/zawen.html $1/zawen. php
RewriteRule ^ (. *)/shige.html $1/shige. php
RewriteRule ^ (. *)/riji.html $1/riji. php
RewriteRule ^ (. *)/xiaoshuo.html $1/xiaoshuo. php
RewriteRule ^ (. *)/contact.html $1/contact. php

Summary: The URL rewriting engine and specifying some Rewrite Rules., Try Faking URL Suffix (forged URL Suffix), it looks very static, improve security and SEO friendliness.
4. Restart apache.
Windows httpd. conf is very easy to find, in the conf directory (I mean if you do not use the integration package)
In Linux, httpd. conf is included in the opt/lampp/etc directory (Xampp is recommended in linux and installed in the opt directory according to the package)
Restart the above job and click OK.
Login as: root
Server refused our key's password:
Last login: Thu Jul 21 14:26:26 2011 from
[Root @ XXXXX ~] # Who
Root pts/0 (
[Root @ XXXXX ~] #/Opt/lampp restart
Stopping XAMPP for Linux 1.6.4...
XAMPP: Stopping Apache with SSL...
XAMPP: Stopping MySQL...
XAMPP: Stopping ProFTPD...
XAMPP stopped.
Starting XAMPP for Linux 1.6.4...
XAMPP: Starting Apache with SSL (and PHP5 )...
XAMPP: Starting MySQL...
XAMPP: Starting ProFTPD...
XAMPP for Linux started.
Just wait.
5. Some code instructions:
<? Php
Echo "<tr> ";
$ I = $ row ['id']; // id column in Database Table insun4, ....
Echo "<td> <a href = \" ii.html \ ">". $ row ['title']. "</a> </td> ";
// Echo "<td> <a href = \" page. php? Id = $ I \ ">". $ row ['title']. "</a> </td> ";
// Echo "<td> <a href = \" page. php? Id = $ I \ ">". $ row ['description']. "</a> </td> ";
Echo "<td> <a href = \" ii.html \ ">". $ row ['description']. "</a> </td> ";
Echo "</tr> ";

<? Php
Include 'config. php ';
Set_time_limit (0); // prevents timeout display errors.
Mysql_query ("set names 'gbk'"); // utf8
// $ Url = " /";
$ Gid = $ _ GET ['id'];
$ Query = "select * from insun4 where id = $ gid"; // select output with like. Where link like 'HTTP: //'
// Echo $ query;
$ Queryresult = mysql_query ($ query) or die ("Data query failed"); // execute the query
// Echo var_dump ($ queryresult );

While ($ row = mysql_fetch_array ($ queryresult )){
Echo ($ row ['content']). "<br> ";

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^ (. *)/(%0-9%}1,%}.html $1/page. php? Id = $2
RewriteRule ^ (. *)/index.html $1/index. php
RewriteRule ^ (. *)/wenzhang.html $1/wenzhang. php
RewriteRule ^ (. *)/gushi.html $1/gushi. php
RewriteRule ^ (. *)/sanwen.html $1/sanwen. php
RewriteRule ^ (. *)/zawen.html $1/zawen. php
RewriteRule ^ (. *)/shige.html $1/shige. php
RewriteRule ^ (. *)/riji.html $1/riji. php
RewriteRule ^ (. *)/xiaoshuo.html $1/xiaoshuo. php
RewriteRule ^ (. *)/contact.html $1/contact. php

2. There are two or three methods on the Internet. They all write a Url_rewrite function, and then require. If it doesn't feel good, we don't recommend it. You can search for it.
Generally, apache, nginx, and htaccess are used. php is rarely used to achieve static url. It is troublesome to use php to achieve static url.

If the following is displayed, it means you are not configured properly.

If the following figure appears, it indicates that you have configured the rewrite rule, but the rewrite rule is not correctly written. Check it.

If so, congratulations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.