douxiezha9319 2014-09-11 01:35
浏览 17
已采纳

php-fpm - 如何将某些符号链接作为PHP脚本执行

I am running Apache 2.2 with FastCGI and php-fpm. I am trying to duplicate the following logic:

<FilesMatch "^(admin|api|app)?(_dev)?$">
    #ForceType application/x-httpd-php
    SetHandler php-fcgi
</FilesMatch>

Which allows me to symlink admin.php as admin, so I can remove the .php extension. It seems the only way to do this with php-fpm is to set the security.limit_extension of the www.conf file to empty, however, as the comments indicate, this is a pretty big security hole, in that php code can now be executed from within any file, regardless of extension.

What would be the preferred way to accomplish the above, but still maintain some semblance of security?

  • 写回答

2条回答 默认 最新

  • doumaojin4008 2014-09-29 15:57
    关注

    @Mike, based on your updated answer, something similar to this .htaccess file should be able to handle what you're trying to do:

    # Enable the rewrite engine
    RewriteEngine on
    # Set the rewrite base path (i.e. if this .htaccess will be running at root context "/" or a subdir "/path")
    RewriteBase /
    
    # If the file exists, process as usual.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .* - [NC,L]
    
    # If the dir exists, process as usual (if you don't need this, just comment/remove the next two lines).
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule .* - [NC,L]
    
    # If (requested_file_name).html exists, rewrite to that file instead.
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.*)$ $1.html [QSA,L]
    
    # If (requested file name).php exists, rewrite to that file instead.
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.html [QSA,L]
    
    # If none of the above rules were triggered, fallback to index.php.
    RewriteRule ^(.*)$ index.php [QSA,L]
    

    With a bit of tweaking this should be able to do the job without the need of having to dive into httpd.conf and the <VirtualHost> nor <FilesMatch> directives. Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line