Cloudways托管环境默认禁用.htaccess解析,需在后台Application Settings中将Apache Configuration设为Custom,并完整配置块启用AllowOverride All,再重启Apache。

Cloudways 托管环境默认不启用 Apache 的 .htaccess 解析,直接丢进 .htaccess 文件不会生效 —— 这是绝大多数人在 Cloudways 上配 ThinkPHP 伪静态失败的根源。
Cloudways 上 Apache 不读 .htaccess 怎么办
Cloudways 使用的是 Apache + PHP-FPM 架构,但出于安全和性能考虑,AllowOverride 默认设为 None,即完全忽略项目目录下的 .htaccess。你写的规则再标准也没用。
- 必须登录 Cloudways 后台 → 点击服务器 → “Application Settings” → 找到 “Apache Configuration”(不是 Nginx)→ 切换为 “Custom” 模式
- 在弹出的编辑框里,**不要**只贴
RewriteRule,而是完整覆盖整个块,例如:
<directory>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</directory>
其中 /applications/your-app-name/public 必须替换成你实际的 public 目录绝对路径(可在 Cloudways “Server Access” 页面看到)
- 保存后点 “Restart Apache”,不是 reload —— 只有 restart 才真正重载配置
ThinkPHP 6 的 rewrite 规则要适配 Cloudways 路径结构
Cloudways 的 Web 根目录默认指向 public 子目录,而很多教程给的规则假设根目录就是入口,直接套用会导致 index.php 找错位置或循环重定向。
- 确保你的
.htaccess放在public目录下(不是项目根目录) - 规则中
RewriteBase必须显式声明,否则$1匹配会偏移:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
-
RewriteBase /表示当前public就是 Web 根,所有重写都基于此;漏掉这行,访问/user/login可能被错误拼成/public/index.php/user/login - 如果项目部署在子目录(如
https://site.com/myapp/),RewriteBase应改为/myapp/,且 ThinkPHP 配置中app_host和url_domain_root也要同步调整
Nginx 模式下 Cloudways 的伪静态更简单但容易漏掉 try_files
如果你在 Cloudways 后台把应用类型从 “Apache” 切成了 “Nginx”,那 .htaccess 完全失效,必须改用 Nginx 原生规则 —— 且 Cloudways 的 Nginx 配置模板里默认没有 try_files,直接照搬网上“if (!-e)”写法会触发 404 或无限跳转。
- 进入 “Application Settings” → “Nginx Configuration” → 切换为 “Custom”
- 在
location /块内,**必须用try_files替代if**:
location / {
try_files $uri $uri/ /index.php?s=$uri&$args;
}
- Cloudways 的 Nginx 默认已开启
fastcgi_split_path_info,所以无需额外配PATH_INFO解析 - 如果用了 TP6 的多应用模式(如
route/app/index),确保s=后面的参数格式与pathinfo_depr一致(默认是/,不是-或.)
真正卡住人的从来不是规则本身,而是 Cloudways 把 Apache/Nginx 的底层控制藏在二级菜单里,又默认关闭了最关键的 AllowOverride 和 try_files 支持。改完配置不 restart、.htaccess 放错目录、RewriteBase 漏写 —— 这三处占了 90% 的调试时间。
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!











