使用PHP动态地添加到.htaccess文件? [英] Use PHP to Dynamically Add To .htaccess File?

查看:268
本文介绍了使用PHP动态地添加到.htaccess文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所要做的是自动化与网站上线的过程。这些网站正在使用htaccess的所有动态创建的,所以这里是一个例子:

What I am trying to do is automate the process of going live with websites. These websites are all dynamically created using htaccess, so here is an example:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*)$ /folder%{REQUEST_URI}?%{QUERY_STRING} [QSA,L]

我要做的就是添加域别名的 domain.com 的,然后将其指向我的服务器IP和htaccess文件使得查看什么是在/文件夹。

What I do is add a domain alias for domain.com, and then point it to my server IP and the htaccess file makes it view what is in the /folder.

它工作正常,但我们计划有数百个网站,并加入code的片段来htaccess的手动可以获得$ ​​P $ ptty的讨厌。由于所有我改变是的 domain.com 的和的 /文件夹的,有没有办法用PHP动态添加到.htaccess文件的底部,如果我创建了一个形成并告诉它的域和文件夹,将其添加到htaccess文件的底部?

It works fine but we are planning to have hundreds of websites and adding that snippet of code to the htaccess manually can get pretty annoying. Since all I am changing is domain.com and the /folder, is there a way to use PHP to dynamically add to the bottom of the .htaccess file if I create a form and tell it the domain and the folder, it will add it to the bottom of the htaccess file?

这将节省很多时间。

太感谢了。

推荐答案

我真的不建议让PHP来增加任何事情成的.htaccess,这是一个很大的安全隐患。

I really do not recommend to allow php to add ANYTHING into .htaccess, it's a big security risk.

//but here is your code
$f = fopen(".htaccess", "a+");
fwrite($f, "your content");
fclose($f);

这篇关于使用PHP动态地添加到.htaccess文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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