【问题标题】:Whitelist php script in .htaccess.htaccess 中的白名单 php 脚本
【发布时间】:2017-04-19 19:47:27
【问题描述】:

我整天都在努力让它工作,但我无法让它工作。 我正在使用 October CMS,它会生成以下 .htaccess 文件:

<IfModule mod_rewrite.c>

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

RewriteRule ^(form/contact.php)($|/) - [L]
##
## You may need to uncomment the following line for some hosting environments,
## if you have installed to a subdirectory, enter the name here also.
##
# RewriteBase /

##
## Black listed folders
##
RewriteRule ^bootstrap/.* index.php [L,NC]
RewriteRule ^config/.* index.php [L,NC]
RewriteRule ^vendor/.* index.php [L,NC]
RewriteRule ^storage/cms/.* index.php [L,NC]
RewriteRule ^storage/logs/.* index.php [L,NC]
RewriteRule ^storage/framework/.* index.php [L,NC]
RewriteRule ^storage/temp/protected/.* index.php [L,NC]
RewriteRule ^storage/app/uploads/protected/.* index.php [L,NC]

##
## White listed folders
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !/storage/app/uploads/.*
RewriteCond %{REQUEST_FILENAME} !/storage/app/media/.*
RewriteCond %{REQUEST_FILENAME} !/storage/temp/public/.*
RewriteCond %{REQUEST_FILENAME} !/form/.*
RewriteCond %{REQUEST_FILENAME} !/themes/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/plugins/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/modules/.*/(assets|resources)/.*
RewriteCond !^index.php index.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !/new/.*

##
## Block all PHP files, except index
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule !^index.php index.php [L,NC]
##RewriteCond %{REQUEST_FILENAME} -f
##RewriteCond %{REQUEST_FILENAME} \.php$
##RewriteRule !^contact.php contact.php [L,NC]

##
## Standard routes
##
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

我也有contact.php 文件,位于/form/ 目录中。我想要的是允许在使用 POST 时执行contact.php。使用 wordpress 或 joomla 我没有遇到这样的问题。 另外,有没有学习htaccess的好教程?

【问题讨论】:

    标签: php .htaccess octobercms


    【解决方案1】:

    将行添加到标题为White listed folders 的部分的最后一行RewriteRule 上方

    RewriteCond %{REQUEST_FILENAME} !your-file\.php

    注释掉标题为Block all PHP files, except index的部分

    【讨论】:

      【解决方案2】:

      做这个?我在文件名contact.php 时添加条件。这里是重写教程:https://httpd.apache.org/docs/current/mod/mod_rewrite.html

      ##
      ## Block all PHP files, except index
      ##
      RewriteCond %{REQUEST_FILENAME} -f
      RewriteCond %{REQUEST_FILENAME} \.php$
      RewriteCond %{REQUEST_FILENAME} !^contact.php$ ## this is new condition
      RewriteRule !^index.php index.php [L,NC]
      

      【讨论】:

      • 感谢您的宝贵时间,不幸的是,它似乎无法正常工作 - 我仍然收到 403 错误,当我尝试直接通过浏览器或通过联系表单发送邮件时:/
      • 如果你删除完整的“## Block all PHP files, except index”然后工作吗?
      • 或者添加这个(## Block all PHP files, except index"之前):
      • RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_FILENAME} ^contact.php$ RewriteRule ^contact.php contact.php [L,NC]
      猜你喜欢
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 2016-10-26
      • 2019-02-12
      • 2013-06-11
      • 1970-01-01
      • 1970-01-01
      • 2011-12-01
      相关资源
      最近更新 更多