gpt4 book ai didi

regex - .htaccess 重定向到语言子文件夹

转载 作者:行者123 更新时间:2023-12-03 21:36:06 25 4
gpt4 key购买 nike

我有什么:

  • 安装了两种语言:德语和英语
  • 语言版本通过子文件夹(www.domain.com/de/和 www.domain.com/en/)进行管理
  • 机器:安装了 Typo3 4.5.4/RealUrl
  • mod_rewrite 已启用且有效

我想做什么:

  • 将没有语言子文件夹的请求重定向到德语版本
  • 例如domain.com/any/test/folder/到 domain.com/de/any/test/folder

我尝试了什么:

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

出现的问题:

  • 所有请求都定向到 domain.com/de/index.php
  • 它导致错误 310 (net::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]

关于regex - .htaccess 重定向到语言子文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10064603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com