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

请求协助配置.htaccess:新增特定页面重定向规则

Adding Root/Index.php Redirection to Your Existing .htaccess Config

Hi there! Let's adjust your .htaccess to handle the new root and index.php redirection while keeping your existing rule intact.

First, let's recap your current rule—it works perfectly for redirecting requests like /test to /app/r/$1, but since it's a catch-all, we need to add your new special case before it so it gets priority (RewriteRules process top to bottom).

Here's the updated config (replace http://your-specified-url.com with your actual target URL):

RewriteEngine on

# Redirect root (/) and /index.php to your specified URL
RewriteRule ^(index\.php)?$ http://your-specified-url.com [R=301,L]

# Original rule: redirect all other requests to /app/r/$1
RewriteRule (.*) http://mydomain/app/r/$1 [R=301,L]

Quick breakdown of the new rule:

  • The regex ^(index\.php)?$ targets exactly two scenarios:
    • The empty string (which maps to the root path /)
    • The literal index.php (we escape the dot with \. to avoid matching any character)
  • The [R=301,L] flags do two key things:
    • R=301: Marks this as a permanent redirect (great for SEO; use R=302 temporarily if you're testing changes)
    • L: Tells Apache to stop processing further rules once this one matches—this prevents your catch-all rule from overriding the root/index.php redirect

If your target URL is a relative path on the same domain (like /new-homepage), you can simplify the rule to:

RewriteRule ^(index\.php)?$ /new-homepage [R=301,L]

Just remember to keep the rule order consistent: specific, narrow rules first, followed by broader catch-all rules. This way, visits to http://mydomain/ or http://mydomain/index.php will redirect to your desired URL, while all other requests still follow your original redirection logic.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:51:40