6

基本上,我一直致力于修复损坏的链接。旧链接可能指向http://www.example.com/work/funkystuff,我将它们重定向到http://www.example.com/en/work/funkystuff

以下是这种可怕疾病的症状:

  1. 图像、Css 和 Javascript 中断。控制台告诉我Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/en/".每种类型的“”。

  2. 我在文件的第一行(我的 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 的语言部分不是真正的子目录,而是一个名称。

4

1 回答 1

0

要修复 css MIME 类型,请将以下行添加到您的 htaccess 文件中:

AddType text/css .css

这假定样式表文件名以 .css 结尾。如果没有,请更改它。

于 2012-12-07T15:04:48.430 回答