I migrated my old blog into WordPress, my old cms has a category URL structure like this one


My new CMS has a category structure (permalink set to " No category base")


My htaccess has modified rules for handling amp parameters taken from
Handle "amp" in URLs from a now removed WordPress plugin

# Redirect ?m=
RewriteCond %{QUERY_STRING} ^m=[01]$
RewriteRule (.*) /$1? [R=301,L]

# Redirect old "amp" URLs back to permalink
RewriteCond %{QUERY_STRING} ^(no)?amp(=[01])?$ [OR]
RewriteCond %{REQUEST_URI} /amp/?$
RewriteRule ^/?([^/]+\.html) /$1 [QSD,R=301,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

can htaccess catch old category & tags path /search/label/123456 and redirect them into new url structure https://www.example.com/123456

  • 1
    Aside: Your # Redirect ?m= rule only matches when m= is the only URL parameter (so it only matches the last example, not the first) - is that the intention?
    – MrWhite
    Commented Mar 4, 2022 at 0:59
  • # Redirect ?m= were taken from https://stackoverflow.com/questions/32118568/how-do-i-redirect-url-parameter-m-1 ( to catch ?m=0 &?m=1) ..do you see any problem with the overall htaccess?
    – R freel
    Commented Mar 4, 2022 at 5:52
  • 1
    Not a problem as such, just that, as I mentioned above, your existing rule does not match your first example /search/label/health?m=0?&max-results=8 (I assume that second ? is a typo?), whereas it perhaps looks like it should. However, that rule is kind of trumped by the new rule in my answer anyway.
    – MrWhite
    Commented Mar 4, 2022 at 13:25
  • Thankyou MrWhite
    – R freel
    Commented Mar 4, 2022 at 18:27

1 Answer 1


To redirect /search/label/<something> to /<something> (where <something> is a single path segment) and remove the query string (if any) then you could do the following at the top of the .htaccess file:

RewriteRule ^search/label/([^/]+)$ /$1 [QSD,R=301,L]

Aside: If you are canonicalising the hostname and scheme (ie. HTTPS + www/non-www) then consider redirecting directly to the canonical absolute URL in these external redirects to minimise the number of redirects. For example:

RewriteRule ^search/label/([^/+)$ https://www.example.com/$1 [QSD,R=301,L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.