Apache伪静态怎么写 PHP+Apache伪静态 .php转换成.html


apache伪静态相信各位都不陌生,今天来细细讲解一下

RewriteEngine On
RewriteBase /
RewriteRule article/news/(\d+).html$ news/a/read.php?id=$1
RewriteRule show/(\d+).html$ news/b/read.php?id=$1
RewriteRule n/c-(\d+).html$ news/c/read.php?id=$1
RewriteRule n/m-(\d+).html$ news/d/m.php?id=$1

观察一下上面的代码,没错前面是伪静态地址 后面是php真实解析地址

比如我现在有个网址是:https://www.ityinhu.com/blog.php?id=9

我想让我的网址变成伪静态:https://www.ityinhu.com/blog/9.html

那么伪静态规则就是:

RewriteRule blog/(\d+).html$ blog.php?id=$1

ok,非常简单便捷

2022.8.20 补充内容

上面的只能匹配到数字,全字符匹配伪静态规则:

RewriteRule ^sx/(.*).html$ sx.php?name=$1