基本上,我一直致力于修复损坏的链接。旧链接可能指向http://www.example.com/work/funkystuff
,我将它们重定向到http://www.example.com/en/work/funkystuff
。
以下是这种可怕疾病的症状:
图像、Css 和 Javascript 中断。控制台告诉我
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/en/".
每种类型的“”。我在文件的第一行(我的 doctype 所在的位置
Uncaught SyntaxError: Unexpected token <
)上收到关于“”的奇怪错误。index.php
这让我认为它甚至没有将我的 .php 文档解释为 .php 文档......
根据我从 Google 会话中收集到的信息,这不应该发生。我的链接是绝对的(由 php 回显),并且我有 RewriteCond 仅重定向不存在的文件和目录(第 4 行和第 5 行)。
所以,是的,这就是我的 .htaccess 的样子。
# enable awesome urls. i.e.:
# http://example.com/about-us/team
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# make sure to set the RewriteBase correctly
# if you are running the site in a subfolder.
# Otherwise links will break.
#
# If your homepage is http://example.com/mysite
# Set the RewriteBase to:
#
# RewriteBase /mysite
#
RewriteBase /
# Redirect key areas of the site before localisation.
RewriteRule ^work/(.*)$ /en/work/$1 [NC,R=301,L]
RewriteRule ^news/(.*)$ /en/news/$1 [NC,R=301,L]
RewriteRule ^about/(.*)$ /en/about/$1 [NC,R=301,L]
RewriteRule ^careers/(.*)$ /en/careers/$1 [NC,R=301,L]
RewriteRule ^contact/(.*)$ /en/contact/$1 [NC,R=301,L]
RewriteRule ^update-twitter/(.*)$ /en/update-twitter/$1 [NC,R=301,L]
# redirect everything to index.php
RewriteRule ^(.*) index.php [L]
我希望有人知道这可能是什么,因为我很困惑。
编辑:我觉得我应该添加更多信息。
我们正在使用一个名为 Kirby 的 CMS,现在开始转向该网站的多语言版本。通过自动检测浏览器语言并将用户从域重定向到域/语言,Kirby 可以为我们简单地做到这一点。
问题是我们使用重定向使事情复杂化。URL 的语言部分不是真正的子目录,而是一个名称。