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>
相关推荐
liliangcsdn9 分钟前
linux pip/conda 修改默认cache位置
linux·运维·pip
凡小烦30 分钟前
Retrofit源码解析
android·面试
_祝你今天愉快34 分钟前
Java垃圾回收(GC)探析
android·java·后端
mortimer43 分钟前
记一次网站服务器无缝扩容:利用软链接实现零停机数据迁移
linux·运维
Dontla1 小时前
docker desktop入门(docker桌面版)(提示wsl版本太低解决办法)
运维·docker·容器
qq_393828221 小时前
苹果MAC 安卓模拟器
android·软件需求·模拟器
恋猫de小郭2 小时前
用 AI 把一个五年前的 RN 项目,从 0.61.3 升级到 0.74.0 是一种什么样的体验
android·前端·react native
没有bug.的程序员2 小时前
《Spring Boot应用工程化提升:多模块、脚手架与DevTools》
java·运维·spring boot
Kapaseker2 小时前
如果你还不懂 Kotlin Flow,这里有一万字
android·kotlin
大山运维2 小时前
免费非常好用的录屏软件,体积小
运维