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>
相关推荐
weixin_307779139 分钟前
Jenkins GitHub插件1.45.0:深度集成与实践指南
运维·云原生·云计算·jenkins
小小哭包6 小时前
Nginx配置文件nginx.conf中文详解
运维·nginx
weixin_431697206 小时前
onlyoffice预览nginx代理的静态文件
运维·nginx
杨云龙UP6 小时前
从0搭建Oracle ODA NFS异地备份:从YUM源到RMAN定时任务的全流程
linux·运维·数据库·oracle
DN金猿6 小时前
恢复 Linux 上误删除的文件
linux·运维·服务器
6***A6637 小时前
Nginx 反向代理配置
运维·nginx
远瞻。7 小时前
【环境配置】Ubuntu系统安装cuda
linux·运维·ubuntu
kyle~8 小时前
Linux---<unistd.h>类Unix系统编程核心头文件
linux·运维·unix
bendan508 小时前
服务通过docker部署后,调用确定相互调用的URL
运维·docker·容器
闲人编程8 小时前
OpenAPI/Swagger规范与API文档自动化
运维·自动化·json·swagger·schema·openapi·codecapsule