2

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

https://www.example.com/search/label/health?m=0?&max-results=8
https://www.example.com/search/label/health?updated-max=2015-03-19T23:13:00-07:00&max-results=20&start=20&by-date=false
https://www.example.com/search/label/health/feed/rss2/
https://www.example.com/search/label/health
https://www.example.com/search/label/health?m=1

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

https://www.example.com/health
https://www.example.com/health/feed
https://www.example.com/health/page/1

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]
</IfModule>

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

4
  • 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
    Mar 4 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
    Mar 4 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
    Mar 4 at 13:25
  • Thankyou MrWhite
    – R freel
    Mar 4 at 18:27

1 Answer 1

2

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]
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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