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 None 将None改为 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>
相关推荐
hunterandroid14 分钟前
[Android 从零到一] Glide 图片加载原理:三级缓存、生命周期绑定与内存优化
android
码完就睡23 分钟前
Linux——以太网协议
运维·服务器·网络·1024程序员节
时间售卖铺27 分钟前
MySQL 日志管理
运维·数据库·mysql·云原生
法的空间35 分钟前
AI 编程时代,为什么 Dart 分析会拖慢大型项目的开发
android·flutter·ios
晴天的雨.99244 分钟前
【Linux】make & Makefile 核心知识点
linux·运维·服务器
鱼儿也有烦恼1 小时前
客户端应用架构模式
android·架构
丘山望岳1 小时前
Linux基础指令入门篇
linux·运维·服务器
hhhjhl1 小时前
Zod 跨端三方库仓颉适配全流程
linux·运维·ubuntu
翔云1234561 小时前
Gaea(小米MySQL Proxy)整体架构
运维·数据库·mysql
程序员清风1 小时前
LibreChat 实战:用 Docker 搭建可扩展的多模型对话平台
运维·docker·容器