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:
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.
points to
http://example.com/help/work/
(/index.html
probably, depending on your webserver config).?city=Washington&state=DC
is called a query string and is passed along with the request to your server, but not as part of the URL itself. So, you can just have anindex.html
page, and use the query string from there.If you’re using PHP, the variables will be available as
$_GET['city']
and$_GET['state']
. Don’t forget to check if they exist first before trying to access them. For example:If you are not using any “backend languages”, you can use JavaScript to access the parameters. See this, or maybe this library.