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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

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

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

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

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles