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. UseTemporaryif 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/$1rewrites to the captured portion of the URL.R=301triggers a permanent redirect, andLtells 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/1maps to that captured value. permanentsends a 301 redirect; useredirectfor 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
相关产品推荐
相关产品推荐

