.htaccess AddType 不起作用

.htaccess AddType does not work

本文关键字:不起作用 AddType htaccess      更新时间:2023-09-26

我为我正在工作的网站的urlrewrite创建了.htaccess文件。添加 .htaccess 后,它停止加载 JavaScript s 和 CSS s。所以我然后添加了AddType text/css .cssAddType text/javascript .js.但是我得到了同样的错误。以下是我的.htaccess代码:

<IfModule mod_rewrite.c>
RewriteBase /downsouthlk.comV3/
RewriteEngine On
AddType text/css .css
AddType text/javascript .js
#Turn on the rewriting engine 
RewriteRule ^admin/dash/?$ /admin/dash.php [NC,L]
RewriteRule ^admin/addcity/?$ /admin/addCity.php [NC,L]

</IfModule>

这是我从chrome开发人员选项中得到的错误:

资源解释为脚本,但使用 MIME 类型传输文本/网页

资源解释为样式表,但以 MIME 类型传输文本/网页

你的问题是在你的css/js链接中使用相对链接。确保在css,js,图像文件中使用绝对路径,而不是相对路径。这意味着您必须确保这些文件的路径以http://或斜杠/开头。

或者,您可以尝试将其添加到页面的HTML标题中:<base href="/" />

您需要将服务器配置为使用


Content-Type: application/javascript

使用 AddHandler

AddHandler text/css .css添加类型文本/CSS .cssAddHandler text/javascript .jsAddType text/javascript .js