的.htaccess重定向到语言子文件夹(.htaccess redirect to languag

2019-09-16 09:59发布

我有的:

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

我想做的事:

  • 重定向没有语言的子文件夹请求到德语版
  • 例如domain.com/any/test/folder/到domain.com/ /任何/测试/文件夹

我的尝试:

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

发生的历史问题:

  • 所有请求都是针对domain.com/de/index.php
  • 它导致了错误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]

所以,我该怎么办?

Answer 1:

那这个呢:

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


Answer 2:

你为什么不使用的东西更简单,就像这样:

# if user didn't specify a valid language subfolder
RewriteCond %{REQUEST_URI} !^/(en|de)/
# redirect user to default language subfolder
RewriteRule ^(.*)$ /de/$1 [L,R=301]


Answer 3:

你其实并不需要使用htacces,你可以在你的realUrl配置中配置此行为。 只要定义这部分在你的配置阵列:

    'preVars' => array(
      array(
        'GETvar' => 'L',
        'valueMap' => array(
            'de' => '0',
            'en' => '1',
            'fr' => '2',
            ),
        'valueDefault' => 'de',
        ),
),

这会给你一个重定向到../德/ ...



文章来源: .htaccess redirect to language subfolder