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>
相关推荐
鹤落晴春8 分钟前
RH124问答5:管理本地用户和组
linux·运维·服务器
難釋懷1 小时前
Nginx对客户端的限制
运维·nginx
乐世东方客1 小时前
备份脚本记录(binlog文件+mysql+mongo)
android·数据库·mysql
华奥系科技1 小时前
汛期城市内涝治理:智慧水务如何重塑防汛“安全感”?
大数据·运维·人工智能
IT WorryFree1 小时前
三套 Zabbix7.4 API 可直接复制 params 模板
运维·服务器·网络
私人珍藏库2 小时前
[Android] 视频下载鸟 v20.02 会员
android·人工智能·智能手机·app·工具·多功能
zh_xuan2 小时前
tv浏览网页工具
android·tv浏览网页
Full Stack Developme2 小时前
Linux rm-rf 执行后,硬盘空间变化
linux·运维·服务器
跨境数据猎手2 小时前
独立站搭建:架构拆解+源码配置+运维复盘
运维·架构
楠目3 小时前
CVE-2017-7529 Nginx Range头整数溢出漏洞利用总结
运维·nginx