PHP是否允许修改.htaccess文件在当前文件夹? [英] Is PHP allowed to modify .htaccess file in current folder?

查看:149
本文介绍了PHP是否允许修改.htaccess文件在当前文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP的Web应用程序位于共同主办。 我的目标是从PHP code PHP页面运行时修改.htaccess文件。 我需要的.htaccess插入一对mod_rewrite的线条进去。

I have a PHP web app located on shared hosting. My goal is to modify .htaccess file from PHP code when the PHP page is running. I need that .htaccess to insert a couple of mod_rewrite lines into it.

现在的问题是,在Windows + Apache的,我可以动态修改.htaccess文件 但在Linux上一样code报告了一个问题,当我尝试访问此文件中的任何 方式(复制或FOPEN):

The problem is that on Windows+Apache I can dynamically modify .htaccess file but the same code on Linux reports a problem when I try to access this file in any way (copy or fopen):

未能打开流:权限被拒绝

我已经给.htaccess文件777权限 - 还是没有结果。 什么$ P $从这样pvents我吗?我怎样才能建立一个解决办法?

I have given .htaccess file 777 permissions - still no result. WHat prevents me from doing this? How can I develop a workaround?

P.S。 我最初的目标是能够添加一个新的重写规则到的.htaccess映射一个 新增CATEGORY_ID新CATEGORY_NAME。

P.S. My initial goal was to be able to add a new RewriteRule into .htaccess that maps a newly added category_id with new category_name.

如果它没有共同主办,我会使用类似RewriteMap指令(在主Apache的配置),将能够访问该映射文件。

If it wasn't shared hosting, I would use something like RewriteMap (in main Apache config) and would be able to access the map file.

这是第一个真正的限制,我已经无法应对用PHP + Apache的,但我希望这是circuventable了。

This is the first real limitation I've been unable to tackle with PHP+Apache, but I hope it's circuventable too.

推荐答案

我想建议别的东西,也适用。而不是写一个规则为每一个特殊的网址,为什么不使用一个对所有?

I want to suggest something else that also works. Instead of writing a rule for every 'special' url, why not use one for all?

我发现了一大堆更容易使用什么词preSS使用:每一个URL重定向到该指数

I found it a whole lot easier to use what wordpress uses: every url is redirected to the index.

所有你需要做的就是,建立索引文件,读取目录加载(可能使用$ _ SERVER ['URI_REQUEST']),并处理它。

All you have to do is, set up the index file, read in the directory that was loaded (perhaps using $_SERVER['URI_REQUEST']), and deal with it.

添加为.htaccess这样的:

add to .htaccess this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

由于这一chunck你有一个系统,在您的处置有所限制。如果你觉得自己重命名你categrory网址,或添加另一种特殊情况,它已经准备好了!

Thanks to that chunck you have a system somewhat unlimited at your disposal. If you ever feel like renaming you categrory url, or add another special case, it's already ready!

这篇关于PHP是否允许修改.htaccess文件在当前文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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