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

Apache2重定向配置问题:排除index.html的域名跳转需求

Fixing Apache Redirect Rule for test.net (Excluding index.html)

Got it, let's straighten out your Apache rewrite config. The current setup isn't working for two key reasons:

  • Your RewriteRule pattern includes the full URL (http://test.net/), but Apache's RewriteRule only matches the path portion of the request (not the protocol or domain).
  • The [^index\.html] syntax is a character class, which matches a single character that isn't in that set of characters—not the entire /index.html path you want to exclude.

Here's the corrected configuration that does exactly what you need:

RewriteEngine On

# Exclude requests for /index.html (case-insensitive)
RewriteCond %{REQUEST_URI} !^/index\.html$ [NC]
# Target only requests to test.net
RewriteCond %{HTTP_HOST} ^test\.net$ [NC]
# Redirect all matching paths to test.test.net
RewriteRule ^(.*)$ http://test.test.net/$1 [R=301,L]

Let's break down each part:

  1. RewriteCond %{REQUEST_URI} !^/index\.html$ [NC]:

    • The ! negates the condition, so this means "if the request URI is NOT exactly /index.html".
    • [NC] makes the match case-insensitive, so /INDEX.HTML or /Index.Html will also be excluded.
  2. RewriteCond %{HTTP_HOST} ^test\.net$ [NC]:

    • Ensures we only apply this rule to requests where the host is test.net (again, case-insensitive).
  3. RewriteRule ^(.*)$ http://test.test.net/$1 [R=301,L]:

    • ^(.*)$ matches any path (empty or with content) after the domain.
    • $1 captures that matched path and inserts it into the target URL, so test.net/xxx becomes test.test.net/xxx.
    • [R=301] sends a permanent redirect (good for SEO; use R=302 if you need a temporary redirect).
    • [L] tells Apache to stop processing further rewrite rules once this one runs.

Bonus: Exclude the root domain (if it defaults to index.html)

If visiting test.net/ (no path) automatically serves index.html and you want to exclude that too, update the first condition to:

RewriteCond %{REQUEST_URI} !^(/index\.html)?$ [NC]

This matches both the empty root path (/) and /index.html, so neither will be redirected.

内容的提问来源于stack exchange,提问作者min.g

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:17:04