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>
相关推荐
yy55273 分钟前
Nginx 安全防护与 HTTPS 部署实战
nginx·安全·https
WangJunXiang65 分钟前
Nginx性能优化与监控笔记
笔记·nginx·性能优化
REDcker18 分钟前
Linux Core Dump 配置与分析指南
linux·运维·服务器
星河耀银海21 分钟前
C++ 异常处理机制:异常捕获、自定义异常与实战应用
android·java·c++
AndroidCode28 分钟前
Android Automotive Power Policy 全流程技术解析
android
IMPYLH28 分钟前
Linux 的 chcon 命令
linux·运维·服务器
aykon34 分钟前
android 扫码优化方案
android
墨狂之逸才34 分钟前
Android TV 智能看板开发踩坑指南:WebView 常见问题与解决方
android
林栩link35 分钟前
Now in Android 现代应用开发实践(三):架构设计(UI)
android·android jetpack
Coolmuster_cn38 分钟前
永久擦除您的 Android
android