【问题标题】:Redirect a folder to another domain via htaccess通过 htaccess 将文件夹重定向到另一个域
【发布时间】:2015-08-28 20:19:26
【问题描述】:

嘿嘿,

首先要做的事情:我发现了两个类似的帖子,但解决方案对我不起作用。那么问题来了:

我有一个 OpenCart 多商店安装。因此,我在 2 个独立的域中经营 2 家商店(一家为德语,一家为英语),文件位于一个文件夹(Web 服务器)中。在将德国商店分离到它自己的域之前,我在 shop1.com/de/xxxx 之类的子文件夹中拥有商店的德语版本。

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

english-shop.com/de/page1 -> German-shop.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}/$1 [R,L=301]

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

# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [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_=$1 [L,QSA]
RewriteRule ^(?:(?:(\w{2})(?:/|\z))?(?:/|\z)?)?(?:([^?]*))? index.php?_route_=$2&site_language=$1 [L,QSA]

如果有人可以帮助我,那就太好了。我确实找到并尝试了几种解决方案,但没有任何效果。谷歌真的为此恨我:(

谢谢,最好的, 德克

【问题讨论】:

  • 请将您的代码简化为此处真正相关的内容。该代码中有很多内容与手头的问题无关

标签: .htaccess redirect opencart


【解决方案1】:
RewriteCond %{HTTP_HOST} !german-shop.de
RewriteRule ^de/(.*) http://german-shop.de/$1 [R,L=301]

当调用 German-shop.de/de/ 时,第一行防止重定向循环。第二行取 /de/ 之后的部分,放在 German-shop.de 之后。

注意:在您的 .htaccess 中,您可以在前面加上 www。并执行 https。也许你需要调整我的线路以防止额外的重定向。

【讨论】:

  • 完成。抱歉,我不太习惯这个平台(多年来一直是被动用户,但我自己从未发布过问题)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-09
  • 1970-01-01
  • 2013-04-01
  • 2015-12-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多