我有什麼:的.htaccess重定向到語言子文件夾
- 有兩種語言安裝:德語和英語
- 語言版本與子文件夾管理(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
- 它導致d錯誤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]
那麼,我該怎麼辦?
這肯定是關係到正則表達式,但我不是在家裏與重寫規則給直接的建議。我嘗試http://martinmelin.se/rewrite-rule-tester/,但它不會識別您的「RedirectMatch永久性」規則。至於ERR_TOO_MANY_REDIRECTS,是否可以再次提供(並再次)提供生成的URL進行轉換? – buckley 2012-04-08 18:11:34
你也可以使用內容協商'Accept-Language:de'頭來幫助確定初始重定向http://httpd.apache.org/docs/2.2/content-negotiation.html甚至是geoip/geodns – 2013-12-12 12:43:01