1

Using the .htaccess file, I would like to redirect www.example.com/fr/ to www.example.com/ but not other French pages that have the /fr/ root (e.g. www.example.com/fr/page-name)

I've tried using Redirect 301 /fr/ https://example.com/ but that redirects all the French pages to the English versions, which I don't want.

Is there a way around this?

MrWhite
  • 12,647
  • 4
  • 29
  • 41
Samuel
  • 13
  • 2

1 Answers1

0
Redirect 301 /fr/ https://example.com/

The mod_alias Redirect directive is prefix-matching, so it redirects everything that simply starts /fr/ and copies everything after the match onto the end of the target URL. It's great for redirecting entire URL branches (or entire sites), but not for specific URLs.

To redirect a specific URL you need to use RedirectMatch, which matches against a regex, instead of simple prefix-matching.

For example:

RedirectMatch 301 ^/fr/$ https://example.com/

Note that if you have existing mod_rewrite directives (ie. RewriteRule) then you may need to use (or may be preferable to use) mod_rewrite instead here.

Reference:

MrWhite
  • 12,647
  • 4
  • 29
  • 41