剧本重写.htaccess文件适用于瓦帕但不共享主机上的网适用于、重写、但不、剧本

2023-09-02 11:42:53 作者:★n1苏凡

我已经写了 CMS ,允许通过政府.htaccess文件的控制权。一切都很好,在我的瓦帕我的计算机和更新发生和的.htaccess改写为设计。然而,在网络上的共享主机上的脚本返回更新/重写页面没有源的空白页。

I have written a CMS that allows for control of the .htaccess file through administration. Everything is fine on my wamp on my computer and the updates occur and the .htaccess is rewritten as designed. However, on the a shared host on the net the script returns the update/rewrite page as a blank page with no source.

通过JS控制台中铬查看它闪烁下面的错误,我能赶上在打印屏幕:

Viewing through the js console in chrome it flashes the following error which I was able to catch in print screen:

虽然更新页面返回空白,500错误闪烁的网站本身不会受到影响,使得尽管发生内部错误。

Though the update page is returned blank and the 500 error flashes the site itself is not affected and renders although an internal error has occurred.

我的问题...有没有可能在的php.ini 或者在服务器上,我不知道这将prevent的一个设置在其他地方。被动态更新htaccess文件?

My question... Is there perhaps a setting in php.ini or somewhere else on the server that I am not aware of that would prevent the .htaccess file from being dynamically updated?

我的WAMP运行PHP 5.5.12,而服务器是5.4

My wamp is running PHP 5.5.12 while the server is 5.4

===问UPDATE ===

=== QUESTION UPDATE ===

该服务器是不承认 r ,因此.htaccess文件被渲染,而不链路断开一行,并注释自行解决。

The server is no recognizing r and as a result the .htaccess file is rendering in a single line without link breaks and is commenting itself out.

下面是原来的code:

Here is the original code:

# Prevent viewing of .htaccess file
    if($view_htaccess == 1){
    $htaccess_code .= "# Prevent viewing of .htaccess file r";
    $htaccess_code .= "<Files .htaccess> r";
    $htaccess_code .= "order allow,deny r";
    $htaccess_code .= "deny from all r";
    $htaccess_code .= "</Files> r";
    $htaccess_code .= " r";
    }

我试过 ñ r r ñ以及...不知道哪里去了从这里

I tried nr and rn as well... not sure where to go from here

感谢您事先的任何援助,

Thanks for any assistance in advance,

皮特

推荐答案

解决的问题:

在瓦帕我的电脑服务器不是 ñ上,但确实承认 r 所以我编程相应。一旦上传到一个500错误是由服务器不承认 r ñ和运行$导致服务器C $ C一起的地方是在评论自己了。

In wamp on my computer the server was not n but did recognize r so I programmed accordingly. Upon uploading to the server a 500 Error was caused by the server not recognizing r or n and running the code together where it was commenting itself out.

虽然我不知道为什么它的工作,我发现的解决方案是保存生成的htaccess code到临时文本文件的拳头然后通过的file_get_contents调用临时文本文件的内容(htaccess的-temp.txt'); 键,然后将其保存到htaccess文件

Although I do not why it worked the solution I found was to save the generated htaccess code to a temporary text file fist then call the contents of the temp text file through file_get_contents('htaccess-temp.txt'); and then save it to the htaccess file.

然而,这导致了另一个问题,即该脚本会自动被添加斜线机器人用户代理斜线互联网忍者这需要一个 str_replace转换(\,\,$ get_htaccess_ code); 被应用到了的file_get_contents返回(htaccess的-TEMP.TXT'); 保存到htaccess文件之前。斜线与需要转义替换。

This however resulted in another issue where the script automatically was adding slashes to the slashes in the robot user agents Internet Ninja which required a str_replace("\", "\", $get_htaccess_code); to be applied to the return of file_get_contents('htaccess-temp.txt'); before saving to the htaccess file. The slash to replace with needed to be escaped.

最后code:

$file_handle = fopen('htaccess-temp.txt', 'w'); 
fwrite($file_handle, $htaccess_code); fclose($file_handle); 
$get_htaccess_code = file_get_contents('htaccess-temp.txt');    
$get_htaccess_code = str_replace("\", "\", $get_htaccess_code);
$file_handle = fopen($level.'.htaccess', 'w'); 
fwrite($file_handle, $get_htaccess_code); fclose($file_handle);

虽然这工作我还是不明白,为什么我必须保存code首先,以文字...为什么都被添加斜线。如果您有任何想法,请发表评论。

Though this works I still do not understand why I had to save the code to text first... and why slashes were being added. If you have any idea please comment.

皮特