简体   繁体   中英

Redirect multiple subfolders/subdirectory to one domain

So I would like to know if it is possible to redirect multiple subdirectories to another domain using htaccess.

Current situation:

  • example.de/de/
  • example.de/nl/
  • example.de/fr/
  • example.de/en/
  • example.de/it/
  • example.de/es/

Ideally with redirects:

  • example.de/de/ --> stays on example.de/de/
  • example.de/ nl / --> example2. com /nl/
  • example.de/ fr / --> example2. com /fr/
  • example.de/ en / --> example2. com /en/
  • example.de/ it / --> example2. com /it/
  • example.de/ es / --> example2. com /es/

I read a little about Apache and its syntax, but I am still far from understanding it entirely. It seems to use regular expressions, but does not use '|' (or).

The website host instructs to write the htaccess as follows, where example.nl/webshop redirects to example.com/shop:

Redirect 301 /webshop http://www.example.com/shop

But I need it to redirect multiple, but not all, subdirectories. Is it possible using regular expressions and if so, how? If not possible to redirect multiple subdirectories, what are the alternatives?

Thanks in advance!

You can use mod-rewrite to redirect your URLs . Try the following in your htaccess file :

RewriteEngine on

#redirect the specified lang paths to another domain
RewriteRule ^(nl|fr|en|it|es)/ https://example2.com%{REQUEST_URI} [NE,L,R=301]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM