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

AWS EC2实例仅首页可路由,后续页面报URL NOT FOUND问题求助

Hey there, let's figure out why only your homepage is working after upgrading PHP from 5.6 to 7.0 on your AWS EC2 instance. That "URL NOT FOUND" error on other pages is almost always tied to Apache configuration changes that come with PHP version updates—here's how to fix it step by step:

1. Make sure mod_rewrite is enabled

Pretty URLs (the kind most apps and CMS use) rely on Apache's mod_rewrite module, and it's possible the PHP upgrade disabled it by accident.

  • Run this command to check if it's active:
    httpd -M | grep rewrite
  • If you don't see rewrite_module (shared) in the output, enable it:
    • For RHEL/CentOS (common on AWS EC2): sudo ln -s /etc/httpd/mods-available/rewrite.load /etc/httpd/mods-enabled/rewrite.load
    • For Debian/Ubuntu: sudo a2enmod rewrite
  • Restart Apache after enabling: sudo systemctl restart httpd
2. Fix the AllowOverride setting in Apache config

Even if mod_rewrite is on, your site's .htaccess file won't work unless Apache allows it via the AllowOverride directive.

  • Open your site's Apache config file (usually at /etc/httpd/conf.d/your-site.conf or /etc/httpd/httpd.conf)
  • Find the <Directory> block pointing to your web root (like /var/www/html). Update it to look like this:
    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    
  • Save the file and restart Apache: sudo systemctl restart httpd
3. Check your .htaccess file

Sometimes the upgrade process can overwrite or break your .htaccess rules, even if PHP 7.0 itself doesn't conflict with them.

  • First, back up your current file: sudo cp /var/www/html/.htaccess /var/www/html/.htaccess.bak
  • If you're using a CMS like WordPress, re-save your permalink settings (Settings > Permalinks) to generate a fresh, compatible .htaccess
  • For custom apps, make sure your rewrite rules are correct. A standard rule for routing all requests to index.php (common in MVC frameworks) looks like this:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    
4. Verify PHP-FPM configuration (if you're using it)

If you switched to PHP-FPM during the upgrade (a common setup for PHP 7.0), misconfiguration here can break routing.

  • Check your Apache config to ensure it's passing PHP requests to PHP-FPM. Look for lines like:
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1
    
  • Confirm the port (9000 is default) matches what PHP-FPM uses. You can check this in /etc/php-fpm.d/www.conf under the listen directive.
  • Restart both services: sudo systemctl restart php-fpm && sudo systemctl restart httpd
5. Dig into Apache error logs for clues

If none of the above works, the error logs will tell you exactly what's going wrong.

  • View the log in real-time: sudo tail -f /var/log/httpd/error_log
  • Try accessing a broken page, then look for new entries. You might see permission issues, missing modules, or invalid rewrite rules that aren't obvious at first glance.

After working through these steps, your site's routing should be back to normal. If you run into specific issues with any of these steps, feel free to share more details!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 06:31:44