我怎样才能把所有的重写x.php到x.css在一​​个特定的目录? [英] How can I turn all rewrite x.php into x.css in a specific directory?

查看:133
本文介绍了我怎样才能把所有的重写x.php到x.css在一​​个特定的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要重写目录中的所有文件,基本上使PHP自己的一些推广CSS代替。我想要做的与该特定目录中的.htaccess文件。

I need to rewrite all the files in a directory and essentially make their extentions css instead of php. I want to do with with a .htaccess file within that specific directory.

什么是这样做的正确的方法以及是否有我需要设置确保文件被读作.css文件的任何特殊的PHP头文件是否正确?

What is the correct method of doing so and are there any special PHP headers I need to set the ensure the file is read as a .css file correctly?

推荐答案

我觉得你更想被internaly改写为 *。CSS 的请求 *。PHP 。因此,尝试这样的:

I think that you rather want requests of *.css to be rewritten internaly to *.php. So try this:

RewriteEngine on
RewriteRule ^(foo/.*)\.css$ $1.php [L]

是这里的特定目录中。

While foo is here the specific directory.

您现在应该明确声明为文本/ CSS输出使用下面的PHP脚本的开始:

You now should explicitly declare the output as text/css using the following at the begin of the PHP script:

<?php
header('Content-Type: text/css;charset=<your charset>');

替换&lt;您的字符集&GT; 用任何字符集/编码您使用的是(或许 ISO-8859-1 UTF-8 )。

Replace <your charset> by whatever charset/encoding you are using (probably ISO-8859-1 or UTF-8).

这篇关于我怎样才能把所有的重写x.php到x.css在一​​个特定的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆