Bitnami环境下PHP MVC网站URL路由配置问题求助
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}!-fdon't work because Apache interprets!-fas part of the filename. Adding a space (%{REQUEST_FILENAME}!-f) tells Apache to check if the requested file doesn't exist. - Added
!-dcondition: 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 toindex.phpas theurlparameter. 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
.htaccessoverrides 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 likeInclude 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 theurlparameter 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.compoints to your server's IP in your/etc/hosts(Linux/macOS) orC:\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

