如果在 url 中找不到任何内容,我正在使用下面的 .htaccess 文件强制重定向到“语言前缀”。因此,如果键入 domain.com/news,它会重定向到 domain.com/en/news - 这很好用。
此规则不应应用于某些文件夹,如图像、swf 和 myphp。它适用于前两个,所以当我访问 domain.com/swf 时,我看到一个目录内容列表并且没有添加“en”。
但是,它不适用于“myphp”文件夹(这是一个 phpmyadmin 安装)。通常它会加载 myphp/index.php 但将文件名添加到规则中没有区别。该页面只是继续加载,但没有任何反应。有谁知道为什么?
RewriteEngine On
RewriteBase /
#force redirect to language specific page
RewriteCond $1 !^(en|fr|nl)$
#dont apply the rule to the assets folders
RewriteCond $1 !^images$
RewriteCond $1 !^swf$
RewriteCond $1 !^myphp$
#redirect to default EN page if no language param is present in URI
RewriteRule ^([^/]+)/.* /en/$0 [L,R=301]
#remove index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteRule ^(.*)$ /index.php?$1 [L]