-3

I want to redirect many URLs in my shop. Here is the example:

/pl/index/12
/pl/index/16
/pl/index/18

and so on.

What would be the rule for .htaccess to rewrite all of trash URLs from the previous version of shop to my main page?

2
  • 2
    Mass redirecting URLs to the home page isn't good user experience, nor is it good for SEO. Users are served better with either a specific redirect to the new location of the content, or with 410 Gone error explaining why it was removed. Google treats redirects to the home page as "soft 404" errors. There is no SEO advantage to putting in generic redirects like this. Commented May 22, 2020 at 17:34
  • Since you mentioned SEO advantage, is there more of it to a 410? and while I agree that redirecting to main is kind of disruptive, what about redirecting to say a higher-level category, or another somewhat related page, do you think the search engines would treat that more kindly than a 4xx? thanks! Commented Apr 4, 2023 at 9:51

1 Answer 1

3

As stated by Stephen, you should rather set a 410 Gone redirection, like this:

# /.htaccess:

Redirect 410 /pl/index/12
Redirect 410 /pl/index/16
Redirect 410 /pl/index/18
# And so on.

Or, if you can identify a pattern in the paths that have to be redirected, you can use the RedirectMatch directive, for example:

# /.htaccess:

# Of course, you **must** adapt this regex to your case.
RedirectMatch 410 ^/pl/index/1[2|6|8]$

If you can identify a pattern in your paths and want to "410-redirect" the users to a specific page explaining what happens with these gone pages, you can use RewriteRule:

# /.htaccess:

# Of course, you **must** adapt this regex to your case.
RewriteRule ^pl/index/1[2|6|8]$ /special-error410-page.html [R=410,L]
2
  • 1
    They say "and so on." Your regex is only going to capture the three specific examples they use. They might be happy with Redirect 410 /pl which would capture everything in the directory. Or they might want the regex: ^/pl/index/[0-9]+$ which would match any numbers in place of of their three example numbers. Commented May 23, 2020 at 10:49
  • @StephenOstermiller, You are right, there are probably many paths to redirect. I provided a simple regex for example with a comment saying that it has to be adapted. With more details from the OP, we might help him to design the right regex.
    – Éric
    Commented May 23, 2020 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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