1

I have over 2000 dynamically generated duplicated pages like this:

https://www.example.com/subfolder/page1.html

and

https://www.example.com/subfolder/page1/

What i am trying to do is redirect all /subfolder/all-pages.html to /subfolder/all-pages/

Since it is very complicated to make those pages canonical as i use a custom script, how do i get to do this? One extra question if you dont mind, would that not be too much redirected pages for Google and SEO? It already hurt my SEO a lot. Thanks!

  • It would be useful to see your existing .htaccess file as this would enable the solution to be better optimised for your particular case. – MrWhite Mar 10 at 15:01
2

I assume you are already linking to the URL of the form: /subfolder/page1/. In which case, you can do something like the following using mod_rewrite near the top of your .htaccess file in the root of your site:

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(subfolder/[^/]+)\.html$ /$1/ [R=302,L]

The RewriteCond directive that checks against the REDIRECT_STATUS environment variable may be required in order to prevent a rewrite loop (although whether this is required or not is dependent on how you are routing/rewriting your URLs later).

Note that this is a 302 (temporary) redirect. Only change to a 301 (permanent) redirect - if that is the intention - when you are sure it's working OK. This avoids any erroneous redirects being cached by the browser.

However, simply having these two URLs accessible should not have "hurt your SEO a lot", providing you were consistent in always linking to one version. (Unless you changed the URL structure later?)

  • thank you @MrWhite , this worked perfectly! i only have concerns now, since this is 302 redirect which is not very SEO friendly, how do i change it to 301? just instead 302 write 301 or what? thanks once again this solved much more problems than only duplicate pages – paranoic Mar 10 at 17:01
  • 1
    @paranoic Yes, that's the change to make. Be 100% sure it's working first, though! – wizzwizz4 Mar 10 at 19:11
  • Thank you @wizzwizz4 – paranoic Mar 11 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.