thinkphp在apache、nginx和iis下的URL重写

apache

xml 复制代码
<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  # RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
  # 下面是正确的
  RewriteRule ^(.)$ index.php?/$1 [QSA,PT,L]
</IfModule>

iis

xml 复制代码
<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>

nginx

c 复制代码
#user  nobody;
worker_processes  1;

# 打开log
error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    # 打开log
    access_log  logs/access.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
	server {
		listen 80;
		server_name localhost;

		root D:/work/public;

		index index.php;

		location / {
			try_files $uri $uri/ /index.php$uri$is_args$query_string;
		}

		location ~..php($|/) {
			fastcgi_split_path_info ^(.+.php)(.)$;
			fastcgi_pass 127.0.0.1:9000;
			# linux 
			# fastcgi_pass unix:/var/tmp/php-fpm/php-fpm.sock;
			fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
			fastcgi_param PATH_INFO $fastcgi_path_info; # TP要这玩意
			include fastcgi_params;
		}
	}
}

https://www.kancloud.cn/manual/thinkphp6_0/1037488

相关推荐
FoldWinCard34 分钟前
D4 Linux 进程 内存 等命令
linux·运维·服务器
番茄育学园1 小时前
2026表格自动化工具实测:四个不同方案,适配不同办公场景
运维·自动化
j7~1 小时前
【Linux 系统】二十.进程间通信(共享内存、消息队列、信号量)
linux·运维·消息队列·共享内存·信号量·system v
小南家的青蛙1 小时前
使用Nginx中配置CRL
nginx·crl
裤兜里有钱2 小时前
关于Xshell连接虚拟机Linux失败的主要原因
linux·运维·服务器
有毒的教程2 小时前
Ansible批量操作自动化完整教程:批量部署服务、配置同步、软件更新实战
运维·自动化·ansible
辞旧 lekkk2 小时前
CMake工程指南(一)
linux·运维·服务器·开发语言·qt·学习·萌新
oushaojun22 小时前
deepseek教我什么是docker
运维·docker·容器
jieyucx2 小时前
Windows11 & Linux 环境Docker部署与镜像拉取效率优化实战指南
linux·运维·docker
Junsir大斗师2 小时前
keepalived实现ubuntu22服务器高可用
运维·ubuntu·iptables·keepalived·二层透明网桥