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>
相关推荐
Pocker_Spades_A7 小时前
每天刷十几个平台的热榜太累了?我用一个页面全部搞定
nginx
恋猫de小郭7 小时前
Flutter 3.41.7 ,小版本但 iOS 大修复,看完只想说:这是人能写出来的 bug ?
android·前端·flutter
Jaygee-8 小时前
个人网盘越来越贵?我用 Nginx 自建了一个 WebDAV
运维·nginx
j_xxx404_8 小时前
面试官灵魂拷问:Linux软链接与硬链接到底有什么区别?(附底层Inode级深度图解)
linux·运维·服务器
麦芽糖02198 小时前
python进阶六 正则表达式
android·python·正则表达式
三少爷的鞋8 小时前
🚀天下苦阻塞久矣之DeliQueue:Android 17 无锁 MessageQueue 的架构重构
android
lThE ANDE14 小时前
最完整版Linux安装Redis(保姆教程)
linux·运维·redis
yyuuuzz17 小时前
企业出海:技术部署与运维避坑
运维
北漂Zachary17 小时前
四大编程语言终极对比
android·java·php·laravel
workflower17 小时前
人机交互部分OOD
运维·人工智能·自动化·集成测试·人机交互·软件需求