Part of my URL structure changed can I rewrite part of a URL in htaccess instead of updating thousands of urls one-by-one by hand?

mywebsite . com /old/component/tag/colorado-sunday-meetings


mywebsite . com** /new/component**/tag/colorado-sunday-meetings

If it was this one url I could 301 it but it’s thousands of urls with that 1 change in the url structure.

I have been looking for examples online but I don’t know if any of these work and where I would modify if so.

Removing the Query String
RewriteRule ^/url /url?

Adding to the Query String
Keep the existing query string using the Query String Append flag, but add var=val to the end.
RewriteRule ^/url /url?var=val [QSA]

Rewriting For Certain Query Strings
Rewrite URLs like to but don’t rewrite if val isn’t present.
RewriteCond %{QUERY_STRING} val
RewriteRule ^/url1 /url2

Modifying the Query String
Change any single instance of val in the query string to otherval when accessing /path. Note that %1 and %2 are back-references to the matched part of the regular expression in the previous RewriteCond.
RewriteCond %{QUERY
STRING} ^(.)val(.)$
RewriteRule /path /path?%1other_val%2

Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!