通过 htaccess 将文件夹重定向到另一个域

Redirect a folder to another domain via htaccess

他,

第一件事:我找到了两个相似的帖子,但解决方案对我不起作用。所以这是问题:

我有一个 OpenCart 多商店安装。所以我 运行 在 2 个不同的域上有 2 家商店(一家是德语的,一家是英语的),文件在一个文件夹(网络服务器)中。在将德国商店分离到它自己的域之前,我在像 shop1.com/de/xxxx.

这样的子文件夹中有德语版本的商店

所以现在我需要一个 htaccess 重定向,将所有德语 URL 转发到新域,例如:

英语商店。com/de/page1 -> 德语商店。de/page1

# Prevent Directoy listing 
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
 Order deny,allow
 Deny from all
</FilesMatch>

RewriteEngine On
RewriteBase /

# append WWW
RewriteCond %{HTTP_HOST} !^www.
RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*) https://www.%{HTTP_HOST}/ [R,L=301]

# delete trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ / [R=301,L]

# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/ [R=301,L]
RewriteCond %{HTTPS} !=off

# OpenCart SEO URL Settings
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
#RewriteRule ^([^?]*) index.php?_route_= [L,QSA]
RewriteRule ^(?:(?:(\w{2})(?:/|\z))?(?:/|\z)?)?(?:([^?]*))? index.php?_route_=&site_language= [L,QSA]

如果有人能帮助我,那就太好了。我确实找到并尝试了几种解决方案,但没有任何效果。 Google 真的很讨厌我 :(

谢谢,最好的, 德克

RewriteCond %{HTTP_HOST} !german-shop.de
RewriteRule ^de/(.*) http://german-shop.de/ [R,L=301]

第一行防止在调用 german-shop.de/de/ 时出现重定向循环。第二行把/de/后面的部分放在german-shop.de.

后面

注意:在您的 .htaccess 中,您可以使用前置 www 来做一些事情。并强制执行 https。也许您需要调整我的台词以防止额外的重定向。