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>
相关推荐
飞奔的瓜牛2 小时前
Nginx 实现TCP与UDP转发:新版与老版本配置详解
tcp/ip·nginx·udp
alexhilton2 小时前
MVI 让屏幕一次只有一个状态
android·kotlin·android jetpack
飞奔的瓜牛3 小时前
Nginx 生产环境运维实践:常见问题、关注要点与日常维护
运维·nginx
二流小码农7 小时前
鸿蒙开发:证书只能创建3个,第4个应用怎么办
android·ios·harmonyos
瑞克-桑切斯8 小时前
Kubernetes 1.28 保姆级新手学习教程
运维·学习·docker·云原生·容器·kubernetes
数据库急诊室_阿哲8 小时前
一次割接后的性能复核记录:基线、样本、回滚点
运维·数据库·dba
忆挽篱笙歌9 小时前
systemV进程通信
linux·运维·服务器
阿杰m9 小时前
Android源码第十七章:PowerManager 与后台任务——锁屏后怎么跑?
android
JMchen1239 小时前
【Android 性能优化实战 60 讲】10 Jetpack App Startup 内核魔改:手写异步懒加载启动框架,根治串行初始化耗时
android·性能优化·源码分析·启动优化·kotlin协程·app startup
2601_9679801110 小时前
python+appium自动化测试如何控制App的启动和退出
android·自动化测试·python·appium·设备调试