nginx伪静态规则写法 nginx wordpress伪静态
nginx伪静态规则写法

nginx作为一个轻量级的网站服务端程序,在很多时候我们需要做一些伪静态设置,下面IT袋小编就给大家分享一下nginx伪静态规则写法以及nginx wordpress伪静态写法,不懂的网站长赶紧来学习吧!

一、首先介绍nginx伪静态规则写法:
我们以三种场景给大家举例:
场景一
将 http://www.abc.com/index.php/front/index/index
重写成 http://www.abc.com/a.html
场景二
将 http://www.abc.com/index.php/front/index/parse?name=itboy&age=18
重写成 http://www.abc.com/parse-itboy-18.html
场景三(同一域名下,需要匹配随时新增的二三级目录,并隐藏index.php的.php后缀)
将 http://z.xx.com/own/xys/index.php/admin/login 以及 http://z.xx.com/2018/gdhp/index.php/login
重写成 http://z.xx.com/own/xys/index/admin/login 以及 http://z.xx.com/2018/gdhp/index/login
建议在nginx/conf目录下新建rewrite.conf配置文件中编写伪静态规则,写完后在域名.conf文件中插入rewrite.conf文件即可(用include rewrite.conf插入)
nginx配置文件如下:
server
{
listen 80;
server_name z.xx.com;
index index.html index.php index.htm index.php default.html default.htm default.php;
root /var/www/apps/z.xx.com;
include rewrite.conf;
include none.conf;
error_page 502 /502.html;
include enable-php-pathinfo.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /var/www/wwwlogs/z.xx.com.log;
error_log /var/www/wwwlogs/error.z.xx.com.log;
}
rewrite.conf文件内容如下:
location /
{
#场景一
#http://www.abc.com/index.php/front/index/index 变成 http://www.abc.com/a.html
rewrite a.html /index.php/front/index/index last;
#场景二
#http://www.abc.com/index.php/front/index/parse?name=itboy&age=18 变成 http://www.abc.com/parse-itboy-18.html
rewrite parse-(\w+)-(\d+).html /index.php/front/index/parse/name/$1/age/$2 last;
#场景三
#http://z.xx.com/own/xys/index.php/admin/login 以及 http://z.xx.com/2018/gdhp/index.php/login 变成 http://z.xx.com/own/xys/index/admin/login 以及 http://z.xx.com/2018/gdhp/index/login
rewrite ^/(\w+)/(\w+)/(.*)$ /$1/$2/index.php?s=$3 last; #针对own目录伪静态规则,$1对应(\w+)部分,$2对应第二个(\w+)部分,$3对应(.*)部分,$代表直至最后
rewrite ^/(\d+)/(\w+)/(.*)$ /$1/$2/index.php?s=$3 last; #针对后期的2018下的子项目伪静态规则
}
二、再来介绍Nginx 设置wordpress 伪静态:
phpstudy集成环境下Nginx模式 wordpress伪静态规则如下,将下面的代码复制到到vhosts-ini之后保存,重启phpstudy服务即可。
location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
如果你已经自定义了站点,那么将上的代码复制到vhosts-ini配置文件中的
server {
listen 80;
省略代码……
在最后一个大括号之前粘贴上面的规则即可
加上之后,保存,重新Nignx就可以了。再打开网站试一下,是不是就正常了呢!
上述分享的nginx wordpress伪静态 及其 nginx伪静态规则写法的全面方法讲解,希望起一个抛砖引玉能解决您生活中的问题吧。
相关阅读
-
网站跳出率是什么意思 网站跳出率怎么计算
很多新手网站长不明白 网站跳出率是什么意思?到底网站跳出率高还是低好? 下面IT袋小编就给大家详细的解答下这个问题。 网站跳出率是什么意思 网站跳出率(Bounce Rate)是评价一个网站性
-
免费搭建自己的网站有哪些 创建网站免费注册的平台
为关注IT袋网的网友们详解免费搭建自己的网站有哪些和创建网站免费注册的平台的相关经验,接下来分享详细内容。 想自己建网站又没有网站编程基础的小伙伴有福啦,本期小熊seo整理了国
-
查看注册表的写入时间 配置注册表数据库损坏修复办法
全面的为大家介绍查看注册表的写入时间和配置注册表数据库损坏修复办法的相关经验,下面为详细的介绍。 想知道你的 Windows10或11设备是否已经为即将到来的 Windows11功能更新做好了准备?您
-
帝国CMS更换域名后批量替换图片域名网址方法
有很多新手网站长在使用 帝国CMS建站的时候,由于做的过程中原来图片等地方使用的是绝对路径,更换域名(网址)后文章中的图片依然是原来更换网址前的域名,最终导致图片无法显示 ,遇


