1、iis伪静态规则
<rule name="OrgPage" stopProcessing="true">
<match url="^((!public).*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(.*)$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?s={R:1}" />
</rule>
public文件夹下存放图片、css、js等不做伪静态处理:<match url=”^((?!public).*?)$” />
其它比如文章,不想使用tp的路径,想实现news/12.html的格式,也需要写伪静态规则
<rule name="news" stopProcessing="true">
<match url="news/([0-9].*)$" />
<action type="Rewrite" url="index.php?s=news/view/c/{R:1}" />
</rule>
- 如果使用的是php8,<action type=”Rewrite” url=”index.php?s={R:1}” />这里是 ?s={R:1};
- 以前的版本php7,这里可以是<action type=”Rewrite” url=”index.php/{R:1}” />;
- 不同的rule ,注意name不同;
2、nginx伪静态规则
location / {
if (!-e $request_filename) {
rewrite cn/honor_([0-9].*)$ /cn.php?s=honor/index/c/$1 last;
rewrite about/([0-9].*)$ /index.php?s=about/index/c/$1 last;
rewrite cn/(.*)$ /cn.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
}
root E:\phpweb\test;
index index.html index.htm index.php;
}
#独立文件夹下程序重写,这里我放置的是后台程序
location /public/man/ {
if (!-e $request_filename){
rewrite ^/public/man/admin.php(.*)$ /public/man/admin.php?s=$1 last;
}
}
#如果不写admin.php 在该文件夹下加入空白的首页文件 index.html或者 index.htm 或者index.php
#if (!-e $request_filename){
# rewrite ^/public/man(.*)$ /public/man/admin.php?s=$1 last;
#}
#}
#这样就是同网站首页一样隐藏了入口文件admin.php
- 后台放到了/public/man/文件夹下,也需要重写;
- if (!-e $request_filename)判断是否是文件、文件夹,不是文件夹或者文件会重写;
- 如果是中英文,要把域名带cn 或者en的放到前边,如下中文在前,默认是英文网站:
rewrite cn/(.*)$ /cn.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
3、Apache伪静态规则
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
#RewriteBase
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(temp/list_([0-9].*)$|temp/list_([0-9]+)_([0-9].*)$)
RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
RewriteRule ^temp/list_([0-9]+)_([0-9].*)$ index.php?s=temp/index/catid/$1/tp/$2 [QSA,PT,L]
RewriteRule ^temp/list_([0-9].*)$ index.php?s=temp/index/list/$1 [QSA,PT,L]
</IfModule>
总结:
看似是3个不同规则,其实弄懂了基本的,其他都是类似的,完全可以复制粘贴稍作修改就可以。