Nginx配置伪静态,URL重写

Nginx配置伪静态,URL重写

[ Nginx ]

在Nginx低版本中,是不支持PATHINFO的,但是可以通过在Nginx.conf中配置转发规则实现:

复制代码
location / { // …..省略部分代码
   if (!-e $request_filename) {
           rewrite  ^(.*)$  /index.php?s=/$1  last;
    }
}

[ IIS ]

如果你的服务器环境支持ISAPI_Rewrite的话,可以配置httpd.ini文件,添加下面的内容:

复制代码
RewriteRule (.*)$ /index\.php\?s=$1 [I]

在IIS的高版本下面可以配置web.Config,在中间添加rewrite节点:

复制代码
<rewrite>
 <rules>
 <rule name="OrgPage" stopProcessing="true">
 <match url="^(.*)$" />
 <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/{R:1}" />
 </rule>
 </rules>
 </rewrite>

IIS URL重写,导入规则

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*) index.php?s=1 [L]

[ Apache ]

  1. httpd.conf配置文件中加载了mod_rewrite.so模块
  2. AllowOverride NoneNone改为 All
  3. 把下面的内容保存为.htaccess文件放到应用入口文件的同级目录下
复制代码
<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
相关推荐
不会写DN13 分钟前
PHP 中的文件读写与上传
android·开发语言·php
last demo1 小时前
mysql
运维·数据库·mysql·oracle
灰阳阳2 小时前
Dockerfile实践-构建Nginx镜像
运维·nginx·docker·dockerfile
冬奇Lab2 小时前
Android 15音频子系统(七):音量控制系统深度解析
android·音视频开发
Johnstons2 小时前
网络流量监控工具怎么选
运维·网络·网络故障排除·网络流量分析·网络性能监控
信创DevOps先锋5 小时前
中国DevOps工具链选型新趋势:合规、协同与生态融合的平衡之道
运维·gitee·devops
白鸽梦游指南6 小时前
docker镜像优化
linux·运维·docker
陳10306 小时前
Linux:基础开发工具
linux·运维·服务器
IT界的老黄牛6 小时前
Prometheus + Grafana + AlertManager 监控体系搭建:Docker 一把梭
运维·grafana·prometheus
方白羽7 小时前
Android NFC 功能集成-读卡器模式
android·app·客户端