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

URL Rewrite Redirect技术求助:移除路径中NM的重定向配置疑问

Fixing the /NM/ Path Redirect

Hey Charles, let's sort out this URL redirect for you! Your goal is to strip the /NM/ segment from the path while preserving all the query string parameters (like that reset token) — totally doable. Here's how to set this up based on your server environment:

IIS (Using URL Rewrite Module)

If you're running IIS with the URL Rewrite module installed, add this rule to your web.config:

<rewrite>
  <rules>
    <rule name="Remove NM Path Segment" stopProcessing="true">
      <match url="^NM/(.*)" />
      <action type="Redirect" url="{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>
  • The ^NM/(.*) pattern matches any URL starting with /NM/, capturing everything after that segment into a backreference ({R:1}).
  • redirectType="Permanent" sends a 301 status code, which is best for SEO and browser caching. Use Temporary if you only need this redirect short-term.

Apache (Using mod_rewrite)

For Apache servers with mod_rewrite enabled, add these lines to your .htaccess file or server config:

RewriteEngine On
RewriteRule ^NM/(.*)$ /$1 [R=301,L]
  • ^NM/(.*)$ targets paths starting with /NM/, and /$1 rewrites to the captured portion of the URL.
  • R=301 triggers a permanent redirect, and L tells Apache to stop processing further rules once this one runs.

Nginx

In your Nginx server block, add either of these snippets (the second is more efficient for simple redirects):

Option 1: Using rewrite

rewrite ^/NM/(.*)$ /$1 permanent;

Option 2: Using location and return

location ^~ /NM/ {
    rewrite ^/NM/(.*)$ /$1 permanent;
}
  • The ^/NM/(.*)$ pattern captures the part of the URL after /NM/, and /1 maps to that captured value.
  • permanent sends a 301 redirect; use redirect for a temporary 302 if needed.

Quick Notes

  • Make sure your server has the required modules enabled (URL Rewrite for IIS, mod_rewrite for Apache).
  • Test with a temporary redirect first (302) to confirm everything works before switching to permanent (301) — this avoids caching issues during testing.
  • If you have other rewrite rules, place this one at the top so it doesn't get overridden by other logic.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 10:02:19