dongnai5905 2015-06-23 12:01
浏览 34
已采纳

重写.htaccess文件的脚本适用于wamp但不适用于网络上的共享主机

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.

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

error

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.

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?

My wamp is running PHP 5.5.12 while the server is 5.4

=== QUESTION UPDATE ===

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

Here is the original code:

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

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

Thanks for any assistance in advance,

Pete

  • 写回答

1条回答 默认 最新

  • doudouba4520 2015-06-24 13:04
    关注

    ISSUE RESOLVED:

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

    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.

    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.

    The final 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);
    

    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.

    Pete

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。