You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过.htaccess实现files.example.com路径完整转发至Google Site主站

实现方案

这个需求完全可以实现,你只需要在现有.htaccess规则的基础上新增一条域名重定向规则即可,修改后的完整配置如下:

ErrorDocument 400 /index.html
ErrorDocument 401 /index.html
ErrorDocument 403 /index.html
ErrorDocument 404 /index.html
ErrorDocument 500 /index.html

RewriteEngine On
# 原有强制SSL跳转规则
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"

# 新增files.example.com跳转到主站规则
RewriteCond %{HTTP_HOST} ^files\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NE]

规则说明

  • 新增规则放在强制SSL规则之后,可避免产生多余的二次跳转
  • RewriteCond %{HTTP_HOST} ^files\.example\.com$ [NC]:匹配所有访问域名为files.example.com的请求,NC参数表示不区分大小写
  • $1会自动捕获你访问的完整路径,例如访问https://files.example.com/doc/1.pdf会自动跳转到https://www.example.com/doc/1.pdf
  • R=301表示永久重定向,对搜索引擎SEO更友好,如果你还在测试阶段,可以先改成R=302临时重定向,避免浏览器缓存旧规则
  • 该跳转是在你的cPanel服务器上处理完成的,和目标站点是Google Site没有冲突,只要目标站点对应路径存在就可以正常访问

注意事项

修改完配置后建议清理浏览器缓存后再测试,避免之前的301重定向缓存影响验证结果。

内容的提问来源于stack exchange,提问作者Ryder Cragie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 16:15:03