mod_rewrite 更改 MIME 类型 .css/.js -> html
我有 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
但当我这样做时,我收到错误:
当我访问时自然路径(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:
When I access the natural path (sitename/css/edit.php?page=2
) everything works fine.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
虽然这是一个老问题,但我刚刚经历过同样的事情,但是当我使用 RewriteRules 时。
解决方案是:
强制您正在重写的文件的类型。专门针对 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:
To force the type of the files you are rewriting. Targeting css + js specifically and forcing the T=<>
不确定您是否有拼写错误,是否将以下内容更改
为:
Not sure if you had a typo, what about changing:
To:
我知道这是一个老问题,但以防万一有人仍然会寻找答案。
我只是目睹了同样的错误。
协议是:使用 L 参数 mod_rewrite 会将请求指向您指定的位置,但所有 ajax 调用、包含、javascript src 请求将按照您在原始位置下的行为进行操作。
例如,在 Firefox 中使用 LiveHeaders 检查标头,您会发现您的请求指向错误的位置。即:如果在您的 play.php 中链接 javascript,例如
RewriteRule
指向您
,您将看到您的 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
if
RewriteRule
points fromto
you will see that your play.php file will try to include
src="play/myJS.js"
which of course is not there so it returns404
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.
我也遇到了这个问题并找到了解决方案。
如果你的 css / js 文件是用相对路径链接的,你的 RewriteRule 也会影响它们。为了避免这种情况,请引用根目录。换句话说:
变成
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:
becomes