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 小时前
Ubuntu 22.04 版本常用设置
linux·运维·ubuntu
alexhilton4 小时前
Compose中的CameraX二维码扫描器
android·kotlin·android jetpack
杨云龙UP4 小时前
ODA登录ODA Web管理界面时提示Password Expired的处理方法_20260423
linux·运维·服务器·数据库·oracle
songx_995 小时前
Linux基础2
linux·运维·服务器
陈皮糖..6 小时前
27 届运维实习笔记|第三、四周:从流程熟练到故障排查,企业运维实战深化
运维·笔记·sql·nginx·ci/cd·云计算·jenkins
莫白媛6 小时前
Linux在限制敏感命令下的修改用户密码小白版
linux·运维·服务器
eric*16886 小时前
Android15 enableEdgeToEdge 全面屏沉浸式体验
android·edgetoedge
hhb_6187 小时前
C Shell 基础语法与高阶运维实战指南
运维·c语言·chrome
小智社群8 小时前
小米安卓真机ADB对硬件操作
android·adb
嗷o嗷o8 小时前
Android BLE 为什么连上了却收不到数据
android