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

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" in events)
    This means your details.php script won’t receive the correct event parameter 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

  1. Clear your browser cache first (301 redirects are cached heavily)
  2. Visit www.vidtest.com/details.php?event=xyz—it should redirect cleanly to www.vidtest.com/details/xyz
  3. Visit www.vidtest.com/details/xyz directly—it should load the correct content from details.php without 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 QSA flag preserves any extra query parameters you might add (e.g., www.vidtest.com/details/xyz?foo=bar will pass both event=xyz and foo=bar to details.php)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 03:09:56