mod_rewrite 更改 MIME 类型 .css/.js -> html

发布于 2024-11-16 23:38:21 字数 471 浏览 1 评论 0原文

我有 mod_rewrite 问题,我在名为 cms 的目录中设置了一个 .htaccess 文件:

Options +FollowSymLinks 
RewriteEngine on

#rewrite rules for edit
RewriteRule ^edit\/(.*) edit.php?page=$1 [QSA,L]

我想像 sitename.com/cms 这样访问它/edit/2 但当我这样做时,我收到错误:

myErrors to do with mime types

当我访问时自然路径(sitename/css/edit.php?page=2) 一切正常。

任何帮助将不胜感激。

I have an issue with mod_rewrite, I have a .htaccess file set up in directory called cms:

Options +FollowSymLinks 
RewriteEngine on

#rewrite rules for edit
RewriteRule ^edit\/(.*) edit.php?page=$1 [QSA,L]

I would like to access it like so sitename.com/cms/edit/2 but when I do I get errors:

my errors to do with mime types

When I access the natural path (sitename/css/edit.php?page=2) everything works fine.

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

三生池水覆流年 2024-11-23 23:38:21

虽然这是一个老问题,但我刚刚经历过同样的事情,但是当我使用 RewriteRules 时。

解决方案是:

RewriteRule ^bower_components/(.*)\.(css) test/bower_components/$1.css [L,T=text/css]
RewriteRule ^bower_components/(.*)\.(js) test/bower_components/$1.js [L,T=application/javascript]

强制您正在重写的文件的类型。专门针对 css + js 并强制 T=<>

While this is an old issue, i just experienced the same thing but then when i used RewriteRules.

The solution for that turns out to be:

RewriteRule ^bower_components/(.*)\.(css) test/bower_components/$1.css [L,T=text/css]
RewriteRule ^bower_components/(.*)\.(js) test/bower_components/$1.js [L,T=application/javascript]

To force the type of the files you are rewriting. Targeting css + js specifically and forcing the T=<>

吲‖鸣 2024-11-23 23:38:21

不确定您是否有拼写错误,是否将以下内容更改

RewriteRule ^edit\/(.*) edit.php?page=$1 [QSA,L]

为:

RewriteRule ^edit/(.*?)/?$ edit.php?page=$1 [QSA,L]

Not sure if you had a typo, what about changing:

RewriteRule ^edit\/(.*) edit.php?page=$1 [QSA,L]

To:

RewriteRule ^edit/(.*?)/?$ edit.php?page=$1 [QSA,L]
给我一枪 2024-11-23 23:38:21

我知道这是一个老问题,但以防万一有人仍然会寻找答案。
我只是目睹了同样的错误。

协议是:使用 L 参数 mod_rewrite 会将请求指向您指定的位置,但所有 ajax 调用、包含、javascript src 请求将按照您在原始位置下的行为进行操作。

例如,在 Firefox 中使用 LiveHeaders 检查标头,您会发现您的请求指向错误的位置。即:如果在您的 play.php 中链接 javascript,例如

src="myJS.js"

RewriteRule 指向

[siteroot]/play/some_data_here

[siteroot]/play.php?data=some_data_here

,您将看到您的 play.php 文件将尝试包含 src="play/myJS.js"< /code> 当然不存在,所以它返回 404 又名 text/html。

就我而言,我通过添加 R 参数来“修复它”,以便它重定向到新位置。不利的一面是浏览器中的地址将会改变。尝试将 [QSA,L] 更改为 [QSA,L,R]。

希望这会有所帮助。

I know its old question, but just in case someone will still search for an answer.
I just witness same errors.

The deal is: with L parameter mod_rewrite will point request to the location you specified but all the ajax calls, includes, javascript src requests will behave as you where under original location.

Check the headers using LiveHeaders in Firefox for instance and you will see that your requests are pointing to wrong locations. I.e.: if in your play.php you link javascript like

src="myJS.js"

if RewriteRule points from

[siteroot]/play/some_data_here

to

[siteroot]/play.php?data=some_data_here

you will see that your play.php file will try to include src="play/myJS.js" which of course is not there so it returns 404 aka text/html.

In my case I 'fixed it' by adding R parameter so it redirects to new location. Down side of this is that address in the browser will change. Try changing [QSA,L] to [QSA,L,R].

Hope this helps.

无声情话 2024-11-23 23:38:21

我也遇到了这个问题并找到了解决方案。

如果你的 css / js 文件是用相对路径链接的,你的 RewriteRule 也会影响它们。为了避免这种情况,请引用根目录。换句话说:

<link type="text/css" rel="stylesheet" href="css/style.css">

变成

<link type="text/css" rel="stylesheet" href="/css/style.css">

I was having this problem as well and found a solution.

If your css / js files are linked with a relative path, your RewriteRule will also affect them. To avoid this, reference the root directory. In other words:

<link type="text/css" rel="stylesheet" href="css/style.css">

becomes

<link type="text/css" rel="stylesheet" href="/css/style.css">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文