我可以制作动态 .htaccess 文件吗? [英] Can I make a dynamic .htaccess file?

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

问题描述

我可以用 php 生成我的 .htaccess 吗?
我想使用 php 从数据库中的信息动态创建我的 htaccess 文件.
每当我更改一些代码时,它都会让我省去创建新 .htaccess 文件的麻烦.

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.

推荐答案

您可以使用 文件系统读写文件函数,例如:

$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天全站免登陆