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>
相关推荐
Paper_Love19 分钟前
android安全公告网站
android
.道阻且长.22 分钟前
Linux基础IO:理解文件以及回顾C文件接口
linux·运维·服务器·c语言·开发语言·职场和发展
goehou2 小时前
改错一行 fstab,SSH 就再也连不上了
linux·运维·故障恢复·fstab
Csvn3 小时前
Nginx 可观测性与工程化:指标、告警与发布回滚演练
后端·nginx
StarsGreen4 小时前
Android ADB(Android Debug Bridge)命令详解
android
贝锐4 小时前
远程运维如何实现网页触达:制造企业引入向日葵SDK重构机床运维实战
运维·sdk·web
阿健君4 小时前
现代 Android 屏幕适配完全指南
android·kotlin
无奈笑天下5 小时前
银河麒麟高级服务器操作系统【通过 sysctl 调整内核网络参数】操作方法
运维·服务器·网络
软件交付观察室6 小时前
用户关掉手机定位权限后,原生App还能显示哪些位置?
android·ios·移动开发