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

AWS负载均衡器安装SSL证书后无法访问指定PHP页面求助

Troubleshooting & Fixes for PHP Page Redirects to index.php After SSL Setup

Got it, let's walk through the most likely causes and fixes for your issue where specific PHP pages like admin.php and vendor.php are redirecting to index.php after setting up SSL via AWS ALB and ACM. Since your main site and SSL are working fine, the problem is almost certainly in routing rules or web server configuration—here's how to track it down:

1. Check AWS ALB Routing Rules

It’s common to accidentally set up a "catch-all" rule that forces every request to index.php, even for specific pages. Here’s what to do:

  • Log into the AWS Console, navigate to your Load Balancer, and go to the Listeners tab.
  • Look at your HTTPS (443) listener rules:
    • Verify there are explicit rules for /admin.php and /vendor.php that forward traffic to your EC2 target group. If these rules don’t exist, add them—make sure they take priority over any catch-all rules (like a rule matching /*).
    • Confirm your target group’s health checks are passing. If the ALB thinks your EC2 instances are unhealthy, it might trigger unexpected redirects (though this is less likely for your specific case).

2. Validate Your EC2 Web Server Configuration (Apache/Nginx)

This is the most probable culprit. SSL setup can sometimes activate or modify rewrite rules that override access to specific PHP pages.

For Apache Users:

  • Check your .htaccess file (in your site’s root directory) or virtual host config files (under /etc/apache2/sites-available/) for rewrite rules.
    • If you see something like RewriteRule ^(.*)$ index.php [L], this is a catch-all rule that redirects everything to index.php. Add exceptions for your pages:
      RewriteCond %{REQUEST_URI} !^/admin.php
      RewriteCond %{REQUEST_URI} !^/vendor.php
      RewriteRule ^(.*)$ index.php [L]
      
    • Ensure the mod_rewrite module is enabled: run sudo a2enmod rewrite, then restart Apache with sudo systemctl restart apache2.
    • Double-check that your SSL-enabled virtual host has the same permissions and rules as your HTTP one—don’t let the SSL config block access to these pages.

For Nginx Users:

  • Open your site’s config file (under /etc/nginx/sites-available/) and look at the try_files directive.
    • The default try_files $uri $uri/ /index.php?$query_string; will fall back to index.php if a file isn’t found, but if your PHP files exist, this might be a fastcgi or permission issue. Add explicit location blocks for your pages:
      location /admin.php {
          fastcgi_pass unix:/run/php/php8.1-fpm.sock; # Adjust to match your PHP version
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;
      }
      
      location /vendor.php {
          fastcgi_pass unix:/run/php/php8.1-fpm.sock;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;
      }
      
      # Keep the default catch-all for other paths
      location / {
          try_files $uri $uri/ /index.php?$query_string;
      }
      
    • Test your Nginx config with sudo nginx -t to catch errors, then restart it with sudo systemctl restart nginx.

3. Verify PHP File Permissions & Existence

Sometimes the issue is simpler than you think—make sure your files are actually there and accessible:

  • SSH into your EC2 instance, then navigate to your site’s root directory (usually /var/www/html/). Run ls -l to confirm admin.php and vendor.php exist.
  • Check that the files are owned by the web server user (for Apache/Nginx, this is typically www-data):
    • Fix permissions with sudo chown www-data:www-data /var/www/html/admin.php and sudo chown www-data:www-data /var/www/html/vendor.php.
  • Test access directly on the server with curl http://localhost/admin.php. If this fails, you might have a PHP module missing or a syntax error in the PHP file itself.

4. Clear Browser & Redirect Caches

Old redirects can get stuck in browser cache, even if you’ve fixed the server-side issue:

  • Try accessing the pages in incognito/private browsing mode to bypass cached redirects.
  • Use curl -v https://yourdomain.com/admin.php to see the full HTTP response. Look for 3xx status codes and check where the redirect is coming from—this will confirm if it’s a server-side redirect or a client-side cache issue.

5. Double-Check ALB SSL & Listener Setup

While you said SSL is working, it’s worth a quick check:

  • Confirm your ALB’s HTTPS listener is correctly associated with your ACM certificate.
  • Verify the listener is forwarding traffic to the correct port on your EC2 instances (usually 80 if you’re terminating SSL at the ALB, or 443 if you’re re-encrypting traffic to EC2).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 06:56:30