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 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了