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>
相关推荐
MANONGMN14 小时前
Linux 通配符与正则表达式(含实战案例+避坑指南)
linux·运维·正则表达式
勤源科技14 小时前
运维知识图谱的构建与应用
运维·人工智能·知识图谱
jiyuzzz15 小时前
Docker部署WordPress及相关配置
运维·docker·容器
Jerry15 小时前
Compose 为元素赋予动画特效
android
Jeled16 小时前
协程工具类
android·android studio
还不秃顶的计科生17 小时前
linux下conda未安装的解决方法(离线安装linux下的conda)
linux·运维·服务器
爱学习饼18 小时前
CentOS下安装配置JDK24和tomcat11
linux·运维·centos
Super Rookie18 小时前
Tomcat 自动化脚本安装方案
运维·tomcat·自动化
qinxue72218 小时前
Jenkins自动化配置--CICD流水线
运维·自动化·jenkins
阿兰哥19 小时前
【调试篇5】TransactionTooLargeException 原理解析
android·性能优化·源码