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>
相关推荐
玉梅小洋3 分钟前
GitHub SSH配置教程
运维·ssh·github
、BeYourself4 分钟前
Intent :跳转与数据传递的正确打开方式
android·android-studio
灵感菇_7 分钟前
Android 列表控件全面解析:ListView 与 RecyclerView
android·ui
等什么君!9 分钟前
Docker 数据卷:MySQL 数据同步实战
运维·docker·容器
礼拜天没时间.17 分钟前
《Docker实战入门与部署指南:从核心概念到网络与数据管理》:环境准备与Docker安装
运维·网络·docker·容器·centos
每天瞎忙的农民工19 分钟前
Ubuntu 24 安装npm22
linux·运维·ubuntu·npm
2601_9498095926 分钟前
flutter_for_openharmony家庭相册app实战+照片详情实现
android·java·flutter
fundroid30 分钟前
Kotlin 泛型进阶:in、out 与 reified 实战
android·开发语言·kotlin
Android系统攻城狮32 分钟前
Android tinyalsa深度解析之pcm_open调用流程与实战(一百零三)
android·pcm·tinyalsa·音频进阶·音频性能实战·android hal
j_xxx404_34 分钟前
Linux:进程控制(创建/终止/等待/获取退出信息/多进程)
linux·运维·服务器