A brief discussion on implementing pseudo-static in PHP_PHP tutorial

WBOY
Release: 2016-07-13 17:45:18
Original
942 people have browsed it

/**********************
Title: A brief discussion on pseudo-static implementation in PHP
Author:insun
Blog:http://yxmhero1989.blog.163.com
Reference:
PHP implements pseudo-static url 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 PHP pseudo-static pages: http://www.BkJia.com/kf/201108/100056.html


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

The specific implementation method of pseudo-static page in PHP 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 more reasonable arrangements after PHP obtains url parameters http://hi.baidu.com/wd1314521/blog/item/3af604822f1938b70df4d2e3.html

Two methods of php to implement pseudo-static pages (including two methods of url rewriting http://hi.baidu.com/newyorkmen/blog/item/f998131ae4121b0d34fa4167.html/cmtid/ 6becf7c0d5fd6d38e4dd3b08 PHP page implementation static explanation and detailed code http://hi.baidu.com/newyorkmen/blog/item/f387e3b723dddac437d3ca66.html

*/
I recently interned in a company. I used a PHP crawler to crawl website pages and save them to the database. Then I wrote a website to call the database, and then performed SEO, requiring collection, remote data localization, pseudo-static, keyword optimization, no dead links and no islands. ; After finishing, you can join the project team.
The pseudo-static implementation of PHP is actually for SEO (Search Engine Optimization), which means that spiders like Google and Baidu don't like dynamic pages, so when you display them, they are displayed as .html or directories. In fact, it is a php file on the server side. In other words, search engines do not like pages like /page.php?id=4, but like pages like /4.html, which are very friendly to them (conducive to inclusion). Of course, you will not directly create N pieces of html page.
one. So the easiest way
URL rewriting (pseudo-static) under Apache+PHP
1. Check if apache supports mod_rewrite

Look for LoadModule rewrite_module modules/mod_rewrite.so in apache's httpd.conf and remove the # in front of it (if there is one, uncomment it). Under Linux, it is recommended to use the Xampp installation package, which The LoadModule has basically been uncommented, so there is generally no need to change it.
Then use phpinfo() to check the environment configuration and see if mod_rewrite is supported. As shown in the picture:

浅谈PHP实现伪静态 - InSun - Minghacker is Insun

2. Find Options FollowSymLinks in http.conf and change the AllowOverride None to AllowOverride All.
At this time, the troops are divided into two groups. Those with http.conf permissions can add url rewrite rules after http.conf
Such as

RewriteEngine On
RewriteRule ^(.*)/([0-9]{1,}).html$ $1/page.php?id=$2

The second way is to create an .htaccess file in the code root directory. This file is relatively simple to create. There are three methods. The simplest is of course to create 1.htaccess and then open it in Notepad and save it as .htaccess. The other is to rename and ftp under cmd. Software modifications.
3.rewrite rules
Just look at an example and you’ll understand

RewriteEngine On
RewriteRule ^(.*)/([0-9]{1,}).html$ $1/page.php?id=$2

$ is the terminator, write a regular expression in front, $1 gets the first sub-pattern (the stuff inside the parentheses), $2 gets the second sub-pattern stuff.
Friendly reminder ^ is the beginning, don’t forget to add
If there are 2 parameters, it is very simple and you can handle it yourself.
That is to say, if the browser displays 4.html (the link in your file is written as .html), the actual call is page.php?id=4, so that the input fields of the browser are all html, achieving Pseudo-static.
Of course, if you rewrite different regular rules, the displayed url will be different, whichever you like.
Don't add semicolons when you encounter multiple lines. The following is correct:

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


<code style="line-height: 22px"><font face="新宋体">The overview is the URL rewriting engine and specifying some rewriting rules<code style="line-height: 22px"><code style="line-height: 22px"><font face="新宋体">综述就是网址重写引擎和指定一些重写规则</font>., try Faking URL Suffix (fake URL suffix)
, it looks very static, which improves security and SEO friendliness. 4. Restart apache.
Windows httpd.conf is easy to find, it is in the conf directory (I mean if you don’t use the integration package)
Linux has httpd.conf in the opt/lampp/etc directory (generally, it is recommended to use Xampp according to the package under Linux and install it in the opt directory)
Perform the same work as above and restart and it will be ok
login as: root
Server refused our key
root@XXXXX.com's password:
Last login: Thu Jul 21 14:26:26 2011 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 wait.
5. Partial code guidance:

echo "";
$i=$row['id'];//The id column in the database table insun4, for. . . .
echo " ".$row['title']."";
//echo " ".$row['title']."";
//echo " ".$row['description'].""; 
echo " ".$row['description']."";
echo "";
?>

include 'config.php';
set_time_limit(0);//Prevent timeout errors from being displayed.
mysql_query("set names'gbk'");//utf8
//$url = "http://www.jj59.com/";
$gid = $_GET['id'];
$query="select * from insun4 where id = $gid";//Selective output using like.where link like'http://www.jj59.com/yuanchuang/%'
//echo  $query;
$queryresult=mysql_query($query) or die("查询数据失败");//执行查询
//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


二,看到网上有2-3个方法,都是写个Url_rewrite函数,然后require的,感觉不好就不推荐大家了,大家可以去搜索下。
一般都是借助于apache,nginx,htaccess等,很少用php来实现url的静态化,用php来实现静态化比较麻烦。


如果出现下面这样,说明你没配置好。

浅谈PHP实现伪静态 - InSun - Minghacker is Insun
如果出现下面这样,说明你配置好了,只是rewrite规则写的不对,检查下好了。

浅谈PHP实现伪静态 - InSun - Minghacker is Insun
If the following appears, congratulations.

浅谈PHP实现伪静态 - InSun - Minghacker is Insun
浅谈PHP实现伪静态 - InSun - Minghacker is Insun

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478695.htmlTechArticle/************************ Title: Brief Talk PHP implements pseudo-static Author:insun Blog:http://yxmhero1989.blog.163.com Reference: php implements pseudo-static URL http://blog.78999.org/php_sql_asp/php-re...
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!