1

如果在 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]
4

1 回答 1

1

在我看来,当 url 中有更多内容时,由于尝试匹配文件夹名称后的行尾 ($),您可能会遇到问题。如果您在文件夹名称上留下美元符号会发生什么?

于 2010-02-03T13:45:56.620 回答