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

Bitnami环境下PHP MVC网站URL路由配置问题求助

Fixing PHP MVC Routing in Bitnami's httpd-vhosts.conf

Hey John, let's work through this routing issue you're hitting with your PHP MVC setup on Bitnami. First off, I noticed your provided config snippet cuts off mid-RewriteRule, and there are a couple of small but critical syntax issues that are probably breaking your routing. Let's break this down step by step.

First, Fix the Syntax & Complete the Rewrite Rules

Your original config has missing spaces in rewrite conditions and an incomplete rewrite rule—two common gotchas. Here's a corrected, full version of your httpd-vhosts.conf block:

<VirtualHost *:443>
    ServerName dev.example.com
    DocumentRoot "/opt/bitnami/apps/dev/htdocs"

    # Bitnami requires explicit SSL cert paths (update these if using custom certs)
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apache2/conf/server.crt"
    SSLCertificateKeyFile "/opt/bitnami/apache2/conf/server.key"

    RewriteEngine On
    # Fix: Add spaces between condition variable and check (Apache needs this!)
    RewriteCond %{REQUEST_FILENAME}!-f
    RewriteCond %{REQUEST_FILENAME}!-d
    # Complete the rewrite rule to capture the full request path
    RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]

    # Ensure Apache has proper access to your document root
    <Directory "/opt/bitnami/apps/dev/htdocs">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Key Fixes Explained

  • Missing spaces in RewriteCond: Lines like RewriteCond %{REQUEST_FILENAME}!-f don't work because Apache interprets !-f as part of the filename. Adding a space (%{REQUEST_FILENAME}!-f) tells Apache to check if the requested file doesn't exist.
  • Added !-d condition: This skips rewriting requests for existing directories, which prevents unexpected behavior when accessing folders directly.
  • Complete RewriteRule: The ^(.*)$ captures the full request URL path, passes it to index.php as the url parameter. The [QSA] flag preserves any existing query strings, and [L] tells Apache this is the last rule to process for the request.
  • Directory permissions block: Bitnami's Apache has strict default permissions—this block ensures it can access your files and allows .htaccess overrides if you use them later.

Next Steps to Verify

  • Check if your vhost is loaded: Open Bitnami's main httpd.conf (usually at /opt/bitnami/apache2/conf/httpd.conf) and make sure there's a line like Include conf/extra/httpd-vhosts.conf. If not, add it.
  • Restart Apache: Run this command to apply changes:
    sudo /opt/bitnami/ctlscript.sh restart apache
    
  • Test the routing: In your index.php, add a quick debug line to confirm the url parameter is coming through:
    var_dump($_GET['url']); // Should show the requested path, e.g. "home" for dev.example.com/home
    
  • Hosts file check (local dev): If you're testing locally, make sure dev.example.com points to your server's IP in your /etc/hosts (Linux/macOS) or C:\Windows\System32\drivers\etc\hosts (Windows) file.

If you're still having issues, double-check that your DocumentRoot path is correct and that the Bitnami user (usually daemon) has read access to your /opt/bitnami/apps/dev/htdocs directory.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 08:16:11