的.htaccess重定向到语言子文件夹 [英] .htaccess redirect to language subfolder

查看:159
本文介绍了的.htaccess重定向到语言子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么:

  • 在安装有两种语言:德语和英语
  • 语言版本与子文件夹(www.domain.com/de/和www.domain.com/en /)
  • 管理
  • 机:安装TYPO3的4.5.4 / RealUrl
  • 启用mod_rewrite的作品

我想做什么:

  • 在重定向没有语言的子文件夹请求到德语版
  • 例如。 domain.com/any/test/folder/到domain.com/~~V /所有/测试/文件夹
  • redirect requests without language subfolder to the German version
  • e.g. domain.com/any/test/folder/ to domain.com/de/any/test/folder

我的尝试:

RedirectMatch permanent ^/(?!(?:(?:de|en)/))(.*)$ /de/$1

发生的历史问题:

  • 所有的请求定向到domain.com/de/index.php~~V
  • 这导致了错误310(净值:: ERR_TOO_MANY_REDIRECTS)
  • 也许它没有使用TYPO3的htaccess的作品?

我的洞的.htaccess文件:

# Enable URL rewriting
RewriteEngine On

# Change this path, if your TYPO3 installation is located in a subdirectory of the website root.
# RewriteBase /

# Rule for versioned static files, configured through:
# - $TYPO3_CONF_VARS['BE']['versionNumberInFilename']
# - $TYPO3_CONF_VARS['FE']['versionNumberInFilename']
# IMPORTANT: This rule has to be the very first RewriteCond in order to work!
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]

# Stop rewrite processing, if we are in the typo3/ directory.
RewriteRule ^(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]

# Redirect http://example.com/typo3 to http://example.com/typo3/index_re.php and stop the rewrite processing.
RewriteRule ^typo3$ typo3/index_re.php [L]

#301 redirection for language mode
RedirectMatch permanent ^/(?!(?:(?:de|en)/))(.*)$ /de/$1

# If the file/symlink/directory does not exist => Redirect to index.php.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

# Main URL rewriting.
RewriteRule .* index.php [L]

所以,我该怎么办?

推荐答案

怎么样的:

RewriteRule ^/?(?!de/|en/)(.*) /de/$1 [L,R=301]

这篇关于的.htaccess重定向到语言子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆