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

URL重写规则调整需求:添加域名格式主题名称参数

Fixing Your RewriteRule for Domain-Formatted Topic Names

Hey there! Let's work through your rewrite rule issue and get it sorted properly.

First, let's address the immediate problem with your initial proposed rule:

RewriteRule ^topic/([^/]+)$ index.php?page=topic&server_id=$1&name=$2

This won't work because you only have one capture group (([^/]+)), so $2 will be empty. You need to adjust the regex to capture two separate values (the topic name and ID) from the URL path.

Good news about domain-formatted names

Your concern about matching names like example.com is totally valid, but the [^/]+ pattern works perfectly here! That regex matches any character except a forward slash, which includes dots (.), hyphens, and all other characters in a domain name. No issues there.

The Correct RewriteRule Setup

Since you need to pass two parameters in the order topic name first, ID second, your URL structure should look like this:
/topic/your-domain-name.com/123

To capture both values, use a regex with two capture groups separated by a slash:

RewriteRule ^topic/([^/]+)/([^/]+)$ index.php?page=topic&name=$1&server_id=$2
  • ([^/]+) captures the topic name (e.g., your-domain-name.com) into $1
  • The second ([^/]+) captures the ID (e.g., 123) into $2
  • We map these to the name and server_id parameters as needed

Optional: Restrict ID to Numbers (If Applicable)

If your server_id is always a numeric value, you can make the regex more precise to avoid unintended matches:

RewriteRule ^topic/([^/]+)/(\d+)$ index.php?page=topic&name=$1&server_id=$2

(\d+) only matches one or more digits, which adds a layer of validation.

Important Notes

  • Make sure your Apache config has mod_rewrite enabled and that you have RewriteEngine On at the top of your .htaccess or config file.
  • If you absolutely can't use a slash to separate the two parameters (not recommended, since domains contain dots), you'd need a different separator that doesn't appear in either the name or ID—but using slashes is the cleanest, most standard approach for URL path segments.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:37:41