我可以做一个动态的.htaccess文件? [英] Can I make a dynamic .htaccess file?

查看:309
本文介绍了我可以做一个动态的.htaccess文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以让我的.htaccess与PHP产生?
我想用PHP来动态地从数据库中的信息来创建我的htaccess的文件。
它会救我做一个新的.htaccess文件的麻烦时,我改了一下我的code。

Can I make my .htaccess be generated with php?
I would like to use php to dynamicly create my htaccess file from information from the database.
It would save me the trouble of making a new .htaccess file whenever I change a bit of my code.

推荐答案

您可以读取和写入的文件系统功能的文件例如:

You can read and write files with the file system functions, for example:

$data = <<<EOF
RewriteEngine on
RewriteRule …
EOF;
file_put_contents('.htaccess', $data);

但是如果你使用一个静态规则重定向请求到PHP文件则没有休息会更加灵活。

But it would be more flexible if you use one static rule that redirect the requests to your PHP file that then does the rest.

这篇关于我可以做一个动态的.htaccess文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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