【问题标题】:Trailing slash remove bug with htaccess and apache server使用 htaccess 和 apache 服务器的尾部斜线删除错误
【发布时间】:2026-01-17 19:00:01
【问题描述】:
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} ^(.*)/(.*)/exam$
RewriteRule ^(.*)/(.*)/exam$ exampage.php?vname=$1&ecode=$2 [L]

我想要像“mysite.com/hp/000-120/exam”这样的 URL,但上面的代码不起作用 任何身体都可以帮忙吗?

【问题讨论】:

    标签: apache url url-rewriting


    【解决方案1】:

    您可能只需要以下方法就可以逃脱:

    RewriteRule ^/?([^/]+)/([^/]+)/exam$ exampage.php?vname=$1&ecode=$2 [L]
    

    【讨论】:

    • 我在 htaccess 中使用这个规则 "RewriteRule ^/?([^/]+)-certifications/([^/]+)-exams$ certpage.php?cname=$1 [L]"但它不起作用我想要的是“mysite.com/hp-certifications/emc-exam
    • 您的脚本期望通过什么值,因为您的规则将设置 cname="hp"