Rewriting Website URLs
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
---------------------------------------------------------------------
---------------------------------------------------------------------
-
Hi @denverdonate You might want to look at a wildcard redirect: Redirects - Version 78 Documentation - cPanel Documentation 0 -
Just want to make sure I understand with the wildcard redirect.... 1. This redirect is above everything in htaccess. 2. I redirect from the beginning to the end of a URL and require the exact structure such as https : // webitewhateveritis . com/blah/blah to https : // webitewhateveritis . com/blah/newblah if my structure is https : // webitewhateveritis . com/blah/blah/blah.jpg I don't go to /blah.jpg only as far as the url changes. Ok, I'll give that a shot right now... 0
Please sign in to leave a comment.
Comments
2 comments