Home Backend Development PHP Tutorial A brief discussion on implementing pseudo-static in PHP_PHP tutorial

A brief discussion on implementing pseudo-static in PHP_PHP tutorial

Jul 13, 2016 pm 05:45 PM
http php title y accomplish static

/**********************
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...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles