Question

rewriting part of a url

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

to

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 http://askapache.com/url1?var=val to http://askapache.com/url2?var=val 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 other_val 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

Subscribe
Share

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!