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

如何通过.htaccess隐藏URL中的knowledgebase.php?

Solution for Hiding knowledgebase.php in URLs

Here's the correct .htaccess configuration to meet your requirements:

RewriteEngine On

# Redirect direct requests to knowledgebase.php to the root URL, preserving query parameters
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+knowledgebase\.php\s [NC]
RewriteRule ^ /?%{QUERY_STRING} [R=301,L]

# Internally rewrite root and non-file/directory requests to knowledgebase.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /knowledgebase.php [L,QSA]

How This Works:

  1. Redirect Rule:

    • The RewriteCond checks if the actual client request is targeting knowledgebase.php (case-insensitive, so it handles variations like KnowledgeBase.php too).
    • The RewriteRule sends a permanent redirect (R=301) to the root URL (/) while retaining any query parameters (like ?article=1). For testing, use R=302 temporarily to avoid browser caching issues.
  2. Rewrite Rule:

    • The two RewriteCond lines ensure we don't interfere with requests for real files or directories (so your static assets like CSS, images, or other pages load normally).
    • The RewriteRule internally maps any non-file/directory request to knowledgebase.php. The QSA flag appends the original query string to the rewritten URL, so /?article=1 gets passed to knowledgebase.php?article=1 behind the scenes without changing the visible URL.

Key Tips:

  • Confirm mod_rewrite is enabled on your Apache server (most hosting providers have this turned on by default).
  • Clear your browser cache before testing to avoid old redirects messing with your results.
  • Once you verify everything works as expected, keep R=301 for permanent redirects to help with SEO.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 07:48:09