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>
相关推荐
杭州杭州杭州20 分钟前
Docker实验2----4
运维·docker·容器
loitawu22 分钟前
Rockchip Android16 系统裁剪指南
android·android16·android裁剪·系统裁剪·rockchip app
黄昏晓x22 分钟前
Linux----线程池
linux·运维·服务器
袖手蹲36 分钟前
Arduino UNO Q 板载 Nanobot 自动化编程指南之二
运维·自动化
U盘失踪了38 分钟前
termux linux终端模拟器
linux·运维·服务器
额1291 小时前
UBUNTU中nginx反向代理(负载均衡)
nginx·ubuntu·负载均衡
jinanwuhuaguo1 小时前
OpenClaw v2026.3.23 深度技术分析报告:平台地基的加固与成熟度宣言
运维·数据库·人工智能·openclaw
一只自律的鸡1 小时前
【Linux系统编程】信号 kill/raise/alarm/pause/alarm实例/漏桶算法
linux·运维·服务器
Trouvaille ~1 小时前
【项目篇】从零手写高并发服务器(七):定时器TimerWheel与线程池
运维·服务器·网络·c++·reactor·高并发·muduo库
小羊子说1 小时前
关于车机中的升级流程小结(SOC、MCU、4G升级流程)
android·adb·性能优化·车载系统