Apache服务器.htaccess代码触发500错误,URL美化需求求助
Fixing 500 Error & URL Rewriting for Your .htaccess
Hey there! Let's break down why you're hitting that 500 error and get your URL beautification working smoothly. Here are the key issues and fixes:
1. The Direct Cause of the 500 Error
Your final line is an incomplete RewriteCond directive:
RewriteCond %{REQUEST_FILENAME} !...
Apache can’t parse this invalid syntax—it expects a proper condition (like checking if the request isn’t a real file or directory). This is the main reason you’re seeing the internal server error.
2. Parameter Name Mismatch
Looking at your rules:
- Your original URL uses the parameter
event=xyz - But your rewrite rule maps to
details.php?events=$1(note the extra "s" inevents)
This means yourdetails.phpscript won’t receive the correcteventparameter value.
Corrected .htaccess Code
Here’s the fixed version with clear explanations:
Options +FollowSymLinks -MultiViews RewriteEngine On # Custom 404 error page ErrorDocument 404 /errorPages/404.php RewriteBase / # Redirect old query-string URL to the pretty URL (301 permanent redirect) RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+details\.php\?event=([^\s&]+) [NC] RewriteRule ^ details/%1? [R=301,L] # Rewrite pretty URL back to the actual PHP file # Fixed: Changed "events=$1" to "event=$1" to match original parameter name RewriteRule ^details/([^/]+)/?$ details.php?event=$1 [L,QSA] # Skip rewriting if request targets a real file or directory (completes the incomplete condition) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
How to Test
- Clear your browser cache first (301 redirects are cached heavily)
- Visit
www.vidtest.com/details.php?event=xyz—it should redirect cleanly towww.vidtest.com/details/xyz - Visit
www.vidtest.com/details/xyzdirectly—it should load the correct content fromdetails.phpwithout showing the query string
Quick Extra Notes
- If you uncomment the HTTPS/WWW redirect rules later, place them before your URL rewriting rules to avoid conflicts
- The
QSAflag preserves any extra query parameters you might add (e.g.,www.vidtest.com/details/xyz?foo=barwill pass bothevent=xyzandfoo=bartodetails.php)
内容的提问来源于stack exchange,提问作者Developer
相关产品推荐
相关产品推荐

