cakephp .htaccess,mime 类型
我有一个 cakephp 1.2 应用程序 (1.2.2.8120),我试图在某些页面上使用 app/webroot/.htaccess 文件中的这一行代码更改日本手机的 mime 类型:
AddType application/xhtml+xml .xhtml
这适用于直接上传到 webroot 文件夹的 .xhtml 文件,但常规的 cakephp 页面不起作用。
我尝试将相同的 .htaccess 代码行添加到 app/.htaccess 和 /.htaccess 文件中,但它不起作用。 我还添加了行:
header('Content-type: xhtml+xml');
到 app_controller 的 beforeFilter() 方法,但这也不起作用。
提前感谢您提供的任何帮助。
I have a cakephp 1.2 app (1.2.2.8120) and I am trying to change the mime-type for Japanese cell phones on certain pages with this one line of code in the app/webroot/.htaccess file:
AddType application/xhtml+xml .xhtml
This works for .xhtml files uploaded directly to the webroot folder, but regular cakephp pages don't work.
I have tried to add the same .htaccess line of code to the app/.htaccess and /.htaccess files but it did not work.
I also added the line:
header('Content-type: xhtml+xml');
to the beforeFilter() method of the app_controller, but that also did not work.
Thanks ahead of time for any help you can provide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题在于,在普通的 Cake 应用程序中没有涉及
.xhtml
扩展名的文件,因此 Apache 无法识别类型。实际调用的是webroot/index.php
文件,因此您可能需要设置.php
文件的类型。我想我以前见过这种失败的情况。您还可以尝试使用
DefaultType application/xhtml+xml
。在default.ctp
布局中首先设置 PHPheader()
可能是最好的选择。使用 RequestHandler 组件
respondAs()
设置标题应该是最好的选择。 AFAIA 相当于 Apache 标头。The problem is that there's no file involved with an
.xhtml
extension in a normal Cake app, so Apache can't identify the type. What's actually invoked is thewebroot/index.php
file, so you may want to set the type for.php
files. I think I've seen this fail before though.You could also try using
DefaultType application/xhtml+xml
.Setting a PHPheader()
first thing in thedefault.ctp
layout might be the best option though.Using the RequestHandler Components
respondAs()
to set the header should be the best option. AFAIA that's equivalent to an Apache header.请参阅http://www.pagebakers.nl/ 2007/06/05/using-json-in-cakephp-12/
看起来 Cake 抽象了内容类型标头。您只需将 JSON 内容类型切换为 XHTML 内容类型即可。
See http://www.pagebakers.nl/2007/06/05/using-json-in-cakephp-12/
It looks like Cake abstracts content-type headers. You just need to switch the JSON content-type for the XHTML one.