How to achieve pseudo-static web page in php

藏色散人
Release: 2023-03-09 09:24:02
Original
5018 people have browsed it

php实现网页伪静态的方法:首先在服务器根目录创建一个“.htaccess”文件;然后添加内容为“RewriteRule ^index-(\d+)\.html$ index.php?id=$1”即可。

How to achieve pseudo-static web page in php

本文操作环境:Windows7系统、PHP7.1版,DELL G3电脑

.htaccess实现php网站伪静态,百分百可用!

  • 伪静态是啥?

很简单,就是假的静态网页...

例如有个网页是:

www.xxx.com/index.php?id=1
Copy after login

这是动态网页,php后缀的

如果改成:

www.xxx.com/index-1.html
Copy after login

那么这是静态网页

从.php变成.html就是伪静态

  • 那么怎么变呢?

需要在网站代码做手脚吗?

不需要。。。

我们需要在自己的服务器根目录加一个.htaccess文件即可

文件里面的代码如下

RewriteEngine On
#RewriteBase / 
RewriteRule ^index-(\d+)\.html$ index.php?id=$1
Copy after login

然后上传到网站根目录。

但是你的超链接网站代码也要做相应的处理

例如你的php输出超链接部分是这样的:

<?php
echo "<a href=&#39;index.php?id=$id&#39;>超链接</a>";
?>
Copy after login

我们要相应地改成:

<?php
echo "<a href=&#39;index-$id.html&#39;>超链接</a>";
?>
Copy after login

【推荐学习:PHP视频教程

The above is the detailed content of How to achieve pseudo-static web page in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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!