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

部署于AWS Beanstalk的.htaccess在Apache 2.2可用2.4失效排查

需修改的Apache 2.4不兼容配置项
  • 你只替换了第一个<FilesMatch>块的旧访问控制规则,其余8个匹配目录的<Files>块还在使用Apache 2.2专属的deny from all语法,全部要替换为2.4的Require all denied规范写法。
  • 注意:<Files>指令本身不支持匹配路径前缀,你写的<Files 8fjfsuUhhhhh8/*>这类规则属于Apache 2.2时期的非规范用法,在2.4版本中完全不生效,需要统一改为<FilesMatch>来匹配路径,可将8个目录的拦截规则合并为一个块减少冗余。
  • Apache 2.4.49及以上版本默认开启路径遍历防护,你收到的AH10244: invalid URI path (/cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/sh)属于扫描工具的攻击请求被正常拦截的日志,不是配置问题,无需额外处理。
  • 你现有配置的代理规则优先级高于本地文件/PHP请求的判断逻辑,再加上AWS Beanstalk默认Apache配置对根路径访问有权限校验、未配置代理模块权限,才会触发AH01797: client denied by server configuration: /var/www/html/报错,需要调整规则顺序、添加必要的Options配置,同时确认Beanstalk环境已经加载mod_proxy、mod_proxy_http模块。
  • Apache 2.4对THE_REQUEST的正则匹配更严格,原有规则里的空格转义写法需要调整为\s避免规则失效。
完整适配后的.htaccess参考代码
Options -Indexes +FollowSymLinks -MultiViews

<FilesMatch "\.(htaccess|htpasswd|ini|psd|log|sh|crt|gitignore|md)$">
    Require all denied
</FilesMatch>

<FilesMatch "^(8fjfsuUhhhhh8|backups|stats|icons|error|logs|git|\.git)/">
    Require all denied
</FilesMatch>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^blog/(.*)$ https://blog.mysite.com/$1 [R=301,NC,L]

    # 旧站点重定向规则
    RewriteRule ^retailers($|/$) /merchants/ [R=301,NC,L]
    RewriteRule ^faqs($|/) /FAQ/ [R=301,NC,L]
    RewriteRule ^contact($|/) /contact-us/ [R=301,NC,L]
    RewriteRule ^login($|/) /customer-login/ [R=301,NC,L]
    RewriteRule ^bank-vision($|/) /FAQ/ [R=301,NC,L]

    # 旧系统路由优先匹配,避免被代理规则覆盖
    RewriteRule ^(frontend/process/process/components|admin-lf7/ui/ajax|frontend/ajax|8fjfsuUFks988/cron)($|/) - [L]
    RewriteRule ^rt8aglCo7XfQOxxQH2mTDZw45675675675567P27da4t1T1yJIB5Be58ih /admin.php [L]

    # 本地已存在的文件、目录直接放行,不走代理
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\.php[/?\ ]
    RewriteRule .*\.php$ index.php [L]

    # 新站点代理规则
    # 首页请求处理
    RewriteCond %{THE_REQUEST} ^GET\s/\s.*
    RewriteRule . http://mysite.com.s3-website.eu-west-2.amazonaws.com/ [P]

    # 命名页面代理
    RewriteRule ^(merchants|how-it-works|shop-directory|contact-us|terms-of-use|privacy-policy|complaints-policy|careers|FAQ|error)($|/) http://mysite.com.s3-website.eu-west-2.amazonaws.com/$1$2 [P]

    # 静态资源代理
    RewriteRule ^static/(.*)$ http://mysite.com.s3-website.eu-west-2.amazonaws.com/static/$1 [P]
    RewriteRule ^page-data/(.*)$ http://mysite.com.s3-website.eu-west-2.amazonaws.com/page-data/$1 [P]
    RewriteRule ^([^\/]*).js$ http://mysite.com.s3-website.eu-west-2.amazonaws.com/$1.js [P]
    RewriteRule ^icons-(.*)/(.*)\.(png|jpg)$ http://mysite.com.s3-website.eu-west-2.amazonaws.com/icons-$1/$2.$3 [P]

    # 带推广参数的首页请求处理
    RewriteCond %{THE_REQUEST} ^GET\s/\?utm_source=([^\s&]+)
    RewriteRule . http://mysite.com.s3-website.eu-west-2.amazonaws.com/ [P]
    RewriteCond %{THE_REQUEST} ^GET\s/\?ref=([^\s&]+)
    RewriteRule . http://mysite.com.s3-website.eu-west-2.amazonaws.com/ [P]

    RewriteRule . /index.php [L]
</IfModule>

内容的提问来源于stack exchange,提问作者Daniel Baker

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.27 16:54:03