Question
Using Rewrite Rule for multiple 301 redirects
Hi,
FULL DISCLOSURE: I’m VERY new and inexperienced when it comes to doing anything with .htaccess files.
My Question: I have a site that has been programed to dynamically generate copies of a page to fit a location. For instance, “example.com/help/work/” was set up to make about 100 duplicates that look like this: “example.com/help/work/?city=Washington&state=DC” with the city and state dynamically changing with each page.
As you can imagine, this creates tons of duplicate content. I want to consolidate them by 301 redirecting all the pages with a city and state parameter so they point to the original page (example.com/help/work/).
After some research, I was able to find a RewriteRule that helped me do this on a page by page basis, but only with the homepage:
RewriteCond %{QUERY_STRING} ^city=Philadelphia&state=PA$
RewriteRule ^$ http://example.com/? [R=301,L]
With all that said, I have a two part question:
1) Is there a way to write this so that it targets subdirectory pages? (I could only get it to do the index)
2) Is there a way I can use a wildcare like (.*) in a single RewriteRule so “example.com/help/work/?city=Washington&state=DC” and all it’s variations point to the original page (example.com/help/work/)?
Thanks so much!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×