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

Apache 2.4配置URL重定向:Drupal 8站点移除URL参数

Fixing the 301 Redirect for Your Drupal 8 Site

Hey there, let's get that redirect sorted out! The issue with your original RedirectMatch rule is that it doesn't handle query strings the way you think it does—here's why and how to fix it:

Why Your Original Rule Failed

RedirectMatch only matches the path portion of a URL (everything before the ?). The ?=True part of your pattern never gets matched because the ? signals the start of the query string, which isn't included in the path that RedirectMatch looks at.

The Correct Solution Using mod_rewrite

Since we need to target the query string, mod_rewrite is the right tool for the job (it's already enabled for Drupal sites, so you're good to go). Add one of these rules to your .htaccess file (place it before Drupal's default rewrite rules to avoid conflicts):

Option 1: Target the Exact URL You Mentioned

If you only need to redirect the specific URL https://example.com/course/name-course?True (or the typo'd version with an extra =), use this:

RewriteEngine On

# Match URLs where the query string is exactly "True"
RewriteCond %{QUERY_STRING} ^True$
# Redirect to the path without the query string (the ? at the end clears the query string)
RewriteRule ^course/name-course$ https://example.com/course/name-course? [L,R=301]

Option 2: Generalize for All Similar URLs

If you have multiple URLs ending with ?True that need the same treatment, use this broader rule:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^True$
RewriteRule ^(.*)$ https://example.com/$1? [L,R=301]

Important Notes

  • Clear Browser Cache: 301 redirects are cached permanently by browsers, so make sure to clear your cache before testing.
  • Check Drupal's .htaccess: If you're adding this to Drupal's default .htaccess, place the rules above the # Rewrite URLs of the form 'x' to the form 'index.php?q=x' section to prevent conflicts with Drupal's routing.
  • Verify mod_rewrite: Ensure mod_rewrite is enabled in your Apache config (it should be if Drupal is working properly).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 07:16:48