On the implementation of pseudo static _php tutorial in PHP

Source: Internet
Author: User

/*******************
Title: Elementary Introduction to PHP implementation pseudo-static
Author:insun
blog:http:// Yxmhero1989.blog.163.com
Reference:
PHP implements URL pseudo-static http://blog.78999.org/php_sql_asp/php-rewrite.html

php pseudo static (URL rewrite) Apache configuration http://hi.baidu.com/%B9%D6%CA%AF/blog/item/ 2659b6af548923d57cd92ab9.html


Three ways to implement a PHP pseudo-static page: http://www.BkJia.com/kf/201108/100056.html


Implementation of friendly URLs (recommended for vomiting) http://www.BkJia.com/kf/201006/49208.html

php implementation of pseudo-static page http://www.BkJia.com/kf/201108/100058.html

php pseudo-static and anti-injection http://www.BkJia.com/Article/201108/100059.html

php parameter passing and the more reasonable arrangement after PHP gets the URL parameter http://hi.baidu.com/wd1314521/blog/item/ 3af604822f1938b70df4d2e3.html

php implements two methods of pseudo-static pages, including two ways to rewrite URLs http://hi.baidu.com/newyorkmen/blog/item/ f998131ae4121b0d34fa4167.html/cmtid/6becf7c0d5fd6d38e4dd3b08 PHP page for static explanation and detailed code http://hi.baidu.com/newyorkmen/ blog/item/f387e3b723dddac437d3ca66.html

*/
recently internship in a company, with PHP crawler crawl site pages, save to the database, and then write a website call database, and then do SEO, request acquisition, remote data localization, pseudo-static, keyword optimization, no dead chain no island When you're done, you can get into the project team.
PHP Implementation Pseudo-static is actually for SEO (Search engine optimization search engine optimization), that is, like Google and Baidu and other spiders do not like dynamic pages, So when you display the. html or directory of the performance, in fact, the server side is a PHP file. That is to say the search engine does not like/page.php?id=4 this kind of page, but likes/4.html this kind of page, to its very friendly (facilitates collects), of course you do not directly make N HTML page.
One. The simplest way to implement URL rewriting (pseudo-static)
1 under
apache+php. Check if Apache supports mod_rewrite

then use Phpinfo () to view the environment configuration and whether to support Mod_rewrite.


2. Find the options followsymlinks in http.conf and change the allowoverride none back to allowoverride all.
This time the soldier divided two ways, have http.conf permission to add the URL rewrite rule after http.conf
Such as

Rewriteengine on
Rewriterule ^ (. *)/([0-9]{1,}). html$ $1/page.php?id=$2

The second way is to build the. htaccess file in the root of the code, this file is built relatively simple, there are 3 ways, the simplest of course is to build 1.htaccess and then Notepad to open the Save As. Htaccess, the other is cmd under rename and FTP software modification.
3.rewrite rules
Look at an example and you'll understand.

Rewriteengine on
Rewriterule ^ (. *)/([0-9]{1,}). html$ $1/page.php?id=$2

$ is the Terminator, preceded by a regular expression, to get the first sub-pattern (the inside of the parentheses), the second sub-pattern to get the two-mode dongdong.
Friendship Tips ^ is the beginning, do not forget to add the
If there are 2 parameters, it is also very simple, self-processing.
That is, if the browser is displayed in 4.html (the link in your file is written in. html), the actual call is page.php?id=4, so that the browser input field is HTML, to achieve pseudo-static.
Of course, you rewrite the different regular, the URL shown is certainly different, as you like it.
Do not add a semicolon if you meet more than one line. The following is true:

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


综述就是网址重写引擎和指定一些重写规则., trying faking URL Suffix (forged URL suffix), looks very static, improves security and SEO friendliness.
4. Restart Apache.
Windows httpd.conf is very easy to find in the Conf directory (I mean if you don't use the integration pack)
Linux in the OPT/LAMPP/ETC directory has httpd.conf (General Linux recommended XAMPP follow the package, installed in the OPT directory)
Same as the above work restart a bit OK
Login As:root
Server refused our key
Root@XXXXX.com ' s Password:
Last Login:thu Jul 14:26:26 from 112.65.219.75
[Root@xxxxx ~]# who
Root pts/0 2011-07-21 14:32 (112.65.219.75)
[Root@xxxxx ~]#/opt/lampp/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 a moment, please.
5. Some code guidance:

echo "";
$i = $row The ID column of the [' ID '];//database table Insun4, in order to ....
echo "". $row [' title ']."";
echo "". $row [' title ']."";
echo "". $row [' description ']."";
echo "". $row [' description ']."";
echo "";
?>

Include ' config.php ';
Set_time_limit (0);//prevents timeouts from displaying errors.
mysql_query ("Set names ' GBK '");//utf8
$url = "http://www.jj59.com/";
$gid = $_get[' id '];
$query = "SELECT * from insun4 where id = $gid";//selective output with like. Where link like ' http://www.jj59.com/yuanchuang/% '
Echo $query;
$queryresult =mysql_query ($query) or Die ("query data Failed");//Execute Query
echo Var_dump ($queryresult);

while ($row = Mysql_fetch_array ($queryresult)) {
Echo ($row [' content ']). "
";
}
?>


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


Two, see online there are 2-3 methods, are written a url_rewrite function, and then require, feel bad not recommend everyone, we can go to search under.
generally, with the help of apache,nginx,htaccess and so on, seldom use PHP to achieve the static URL, using PHP to achieve static more trouble.


If it appears below, you are not configured properly.


If it appears below, you have configured, but the rewrite rule is not written, check it out.


If it appears below, congratulations.

http://www.bkjia.com/PHPjc/478695.html www.bkjia.com true http://www.bkjia.com/PHPjc/478695.html techarticle /******************* Title: On the implementation of pseudo-static Author:insun blog:http://yxmhero1989.blog.163.com reference:php implement URL pseudo-static Http://blog.78999.org/php_sql_asp/php-re ...

  • 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: info-contact@alibabacloud.com 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.