我正在尝试为多语言网站提供.htaccess结构,使用每种语言的子目录(即www.mysite.com/en/
)。我在使用它时遇到一些困难,在localhost上运行它时遇到问题(因为站点本身不在根目录中),并且默认情况下重定向到“sv”以防语言尚未设置。
这是.htaccess代码:
RewriteEngine On
#Default to "sv/"
RewriteRule !^(.*){2}/ sv%{REQUEST_URI} [L,R=301]
#Rewrite for "properties", EN special articles related to another system
RewriteRule ^properties/(.*)/?$ index.php?language=en&page=object&slug=$1
#Rewrite for "fastigheter", SV special articles related to another system
RewriteRule ^fastigheter/(.*)/?$ /index.php?language=sv&page=object&slug=$1
#EN articles
RewriteRule ^en(.*)$ index.php?language=en&page=article&slug=$1 [L,QSA]
#SV articles
RewriteRule ^(.*)$ index.php?language=sv&page=article&slug=$1 [L,QSA]
RewriteBase /mysite
RewriteRule ^(.+)/(css|img)/(.+)\.(gif|png|jpe?g|css|js)$ $2/$3.$4 [L]
您是否在重写规则中看到任何错误/我是否需要添加一些内容才能使这种结构正常工作?