php - htaccess 重写后 "Unexpected token ' > '"第 1 行(中断 css 和图像)

标签 php .htaccess content-management-system multilingual kirby

基本上,我的目标是修复损坏的链接。旧链接可能指向 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. 我在 Uncaught SyntaxError: Unexpected token < 的第一行收到关于“index.php ”的奇怪错误文件,我的文档类型在哪里。这使我认为它甚至没有将我的 .php 文档解释为 .php 文档...

根据我从 Google session 中收集到的信息,这不应该发生。我的链接是绝对的(由 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 的语言部分不是真正的子目录,而是名称。

最佳答案

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

AddType text/css .css

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

关于php - htaccess 重写后 "Unexpected token ' > '"第 1 行(中断 css 和图像),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13765224/

相关文章:

php - 关于sql查询php

php - 从表中获取列名,它将每列返回两次

php - 使用 php 显示来自 mysql 表的数据

regex - 如何在 htaccess 重写规则正则表达式中添加点?

wordpress - .htaccess 和 WordPress : Exclude folder from RewriteRule

python - Django Mezzanine - 如何在每页有一个自定义模板?

php - 使用 PHP PDO 问题检查表中的条目

php - 遵循 AngularJS/MySQL/PHP 教程。无法将给定的 .HTACCESS 文件转换为等效的 web.config

asp.net-mvc - 如何访问 BetterCMS 管理页面

php - 管理模块的选项方法